cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
tdiehl
Level II

Apply a formula from a list

I would like to use list of formula and apply them to certain columns accordingly.  Currently throw an error:

Send Expects Scriptable Object in access or evaluation of 'Send' , col <<  /*###*/Set Formula

 

Example formula list:

{:Column 7 + 2, :Col1 + 8, :umn 2 * 3, 3, Empty(), Empty(), Empty(), Empty()}

 

For( i = 1, i < ListSize + 1, i++,
	If( i > colSize,
		New Column( "temp" )
	);//create columns to accomidate list size
	col << Set Formula( ms:formulaList[i] );//set column formulas
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Apply a formula from a list

Assuming that the list you showed in your question, is named "formulalist" and it is in the namespace called "ms" I believe the below script will do what you want

For( i = 1, i < ListSize + 1, i++,
	If( i > colSize,
		New Column( "temp" )
	);//create columns to accomidate list size
	Eval(
		Substitute(
				Expr(
					:temp << Set Formula( __formula__ );//set column formulas
				)
		),
		Expr( __formula__ ),
		Parse( Char( ms:formulaList[i] ) )
	);
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Apply a formula from a list

Assuming that the list you showed in your question, is named "formulalist" and it is in the namespace called "ms" I believe the below script will do what you want

For( i = 1, i < ListSize + 1, i++,
	If( i > colSize,
		New Column( "temp" )
	);//create columns to accomidate list size
	Eval(
		Substitute(
				Expr(
					:temp << Set Formula( __formula__ );//set column formulas
				)
		),
		Expr( __formula__ ),
		Parse( Char( ms:formulaList[i] ) )
	);
);
Jim
gzmorgan0
Super User (Alumni)

Re: Apply a formula from a list

Jim provided the Eval(Substitute()) syntax for working with expressions. However, your logic will only work if your list has place holders for current columns. 

 

Also if you create a new column called "temp" and then another it will be called "temp 1"; yet, you are only assigning formulas to column temp.  I attached an example script with logic that might work for you.

 

I often use Parse(Char()) when working with expressions, however, NameExpr() returns the value of the expression, unevaluated and is expecially useful when building expressions.  You should review the Parse and Name Expr() functions.

 

You will see it in the attached script.

      //Parse( Char( formulaList[i] ) )
     NameExpr( formulalist[i] )

 

 

 

tdiehl
Level II

Re: Apply a formula from a list

Thanks, I had tried to use Parse() but looks like Char was the missing piece. I had used Parse for column names but had set those to string when getting names so it worked there. 

 

I did forget to include the column reference in the code there as I had trimmed it down to focus on the issue.  I will definitely look in to how and why both those options work and why it was so difficult to find them.