cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Allow functions such as Dispatch to accept string variables or expressions

Certain functions only accept quoted text arguments, which is annoying when generating large numbers of plots or tables using a script.

It would be nice if something like the following worked -

// k is some procedurally generated string variable

dt << Variability Chart(
	Y( :ycolumn),
	X( :xcolumn),
	SendToReport(
		Dispatch({k}, "2", ScaleBox,
			{Min( 300 ), Max( 470 ), Inc( 10 ), Minor Ticks( 1 )}
))));


Instead, I have to use convoluted code like this - 

Eval(Eval Expr(dt << Variability Chart(
	Y( :ycolumn),
	X( :xcolumn),
	SendToReport(
		Dispatch({Expr(k)}, "2", ScaleBox,
			{Min( 300 ), Max( 470 ), Inc( 10 ), Minor Ticks( 1 )}
))))));


Functions with this problem that I'm aware of - Dispatch, As Column, :Name

 

2 Comments
gzmorgan0
Super User (Alumni)

I'll cast my vote with you regarding Dispatch. However, some of your claims are not true. New Column does not require an Expr. 

 

Currently, the function As Column() only takes a column Name as its argument. Even though  Col << get name returns a string it is my understanding it is not an object name.   

 

Earlier versions of JMP did not have As Column().  Column(txt) could, and can, be used in a formula if it is a Column formula like Col Mean(). However, since most column formulas are executed by row to refer to the row values the formula required the syntax Column(txt)[] or Column(#)[].  I believe AsColumn() was created to reference the vector values. 

 

Since I am a horrible typist, I still like to use the left, right bracket syntax to th right of Column(txt)[]. It is only 2 characters the same as "As"! I am posting this not to cancel out or argue your wish list item, but to provide a simple alternative now.

 

Note the formula syntax, Col Mean() and Col Std Dev() only need a column reference.

 

My rule of thumb, if I am using a variable in a formula use Column()[] or ref[]  or alternately  As Column( Column(txt) ), AsColumn(ref).

 

Names Default To Here( 1 );
exdt = Open( "$SAMPLE_DATA/Big Class.jmp" );
show( exdt:height[1] + :height[2] + Column( "height" )[3] );  //

txt = "weight";
cnme = column(txt); //column ref
exdt[[7,13, 15],txt] = empty();
exdt << get rows where(IsMissing(Column(txt)[]));
exdt << get rows where(IsMissing(As Column(Column(txt))));
exdt << get rows where(IsMissing(cnme));   // will throw an error
exdt << get rows where(IsMissing(cnme[])); //refers to the column values
exdt << get rows where(IsMissing(As Column(cnme))); // will throw an error

show(Col Mean(Column(txt)));

exdt << New Column("MyNewCol "||txt, Formula( ( Column(txt)[] - Col Mean(Column(txt)) )/ Col Std Dev(Column(txt)) ) );
jlg373
Level II

Thank you for the input, and yes, you're right about New Column.  I've edited my original post for clarity.