Choose Language Hide Translation Bar
Highlighted
samir
Level IV

How to store evaluated list in data table script

Hello,

I would like to store a script in a data table so that users can later on open the tables and run the scripts.

My issue s that I do not know how to print in the data table script the values of the variables i use in my original script. I tried with expr, eval,...

The example below shows it clearly: I try to save a DataTableScript that generates a simple graph based on "mylist". but how to save the real string contained in "mylist" ?

Thanks for your help.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
mylist = {"sex" , "age"};

Graph = Variability Chart(
		Y( :weight ),
		X(  eval(mylist) ),
		Max Iter( 100 ),
		Std Dev Chart( 0 ),
		Show Range Bars( 0 ),
		Show Grand Median( 0 ),
		Std Dev Chart( 1 ),
		Points Jittered( 1 ),
		Show Box Plots( 1 ),

	);
	
dt << New Script(
"Test",
Variability Chart(
		Y( :weight ),
		X(  Eval(mylist) ),
		Max Iter( 100 ),
		Std Dev Chart( 0 ),
		Show Range Bars( 0 ),
		Show Grand Median( 0 ),
		Std Dev Chart( 1 ),
		Points Jittered( 1 ),
		Show Box Plots( 1 ),

	);
);
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ian_jmp
Staff

Re: How to store evaluated list in data table script

I tend to (try to) avoid code duplication (seen as a bad thing for the maintainability of code in any programming language), and stick with a few design patterns that I'm familiar with. So, in this spirit, I would do it as shown below. But I'm sure there are many other ways.

NamesDefaultToHere(1);

CurrentDataTable(Open( "$SAMPLE_DATA/Big Class.jmp" ));

// Expression that makes a variability chart
makeVC = 
Expr(
	vc = CurrentDataTable() << Variability Chart(
								Y(:weight),
								X(TBD),
								Max Iter( 100 ),
								Std Dev Chart( 0 ),
								Show Range Bars( 0 ),
								Show Grand Median( 0 ),
								Std Dev Chart( 1 ),
								Points Jittered( 1 ),
								Show Box Plots( 1 )
								);
	);

// Put the required 'x' values in 'makeVC'
mylist = {"sex" , "age"};
SubstituteInto(makeVC, Expr(TBD), Eval(myList));

// Make the chart
makeVC;

// Now save the script that makes the chart using a similar method to the above
saveScript = Expr(CurrentDataTable() << New Script("My Variability Chart", TBD));
SubstituteInto(saveScript, Expr(TBD), NameExpr(makeVC));
saveScript;

 

View solution in original post

6 REPLIES 6
Highlighted
ian_jmp
Staff

Re: How to store evaluated list in data table script

I tend to (try to) avoid code duplication (seen as a bad thing for the maintainability of code in any programming language), and stick with a few design patterns that I'm familiar with. So, in this spirit, I would do it as shown below. But I'm sure there are many other ways.

NamesDefaultToHere(1);

CurrentDataTable(Open( "$SAMPLE_DATA/Big Class.jmp" ));

// Expression that makes a variability chart
makeVC = 
Expr(
	vc = CurrentDataTable() << Variability Chart(
								Y(:weight),
								X(TBD),
								Max Iter( 100 ),
								Std Dev Chart( 0 ),
								Show Range Bars( 0 ),
								Show Grand Median( 0 ),
								Std Dev Chart( 1 ),
								Points Jittered( 1 ),
								Show Box Plots( 1 )
								);
	);

// Put the required 'x' values in 'makeVC'
mylist = {"sex" , "age"};
SubstituteInto(makeVC, Expr(TBD), Eval(myList));

// Make the chart
makeVC;

// Now save the script that makes the chart using a similar method to the above
saveScript = Expr(CurrentDataTable() << New Script("My Variability Chart", TBD));
SubstituteInto(saveScript, Expr(TBD), NameExpr(makeVC));
saveScript;

 

View solution in original post

Highlighted
pmroz
Super User

Re: How to store evaluated list in data table script

Just include the list definition as part of the table script:

dt << New Script(
"Test",
mylist = {"sex" , "age"};
Variability Chart(
		Y( :weight ),
		X(  Eval(mylist) ),
		Max Iter( 100 ),
		Std Dev Chart( 0 ),
		Show Range Bars( 0 ),
		Show Grand Median( 0 ),
		Std Dev Chart( 1 ),
		Points Jittered( 1 ),
		Show Box Plots( 1 ),

	);
);
Highlighted
samir
Level IV

Re: How to store evaluated list in data table script

I can' t : the list is a result of a script

Highlighted
samir
Level IV

Re: How to store evaluated list in data table script

The SubstitueInto does the job !!!

Thank a lot

Highlighted
samir
Level IV

Re: How to store evaluated list in data table script

Hi,

I have an extra question on this matter:

for several reasons, I need to slightly modify the saveScript expression:

I want to add a few lines of code to it like:

 

dt << Clear Select;
    dt << Clear Row States;
    dt << Select Where( ...);
dt2 = dt << subset ....;

 

Then I save the new script in dt2.

I tried to append, or concatenate  the 2 expressions but it did not work :(

Any help ?

Highlighted
txnelson
Super User

Re: How to store evaluated list in data table script

Here is one way that you can put your expressions together

NamesDefaultToHere(1);

CurrentDataTable(Open( "$SAMPLE_DATA/Big Class.jmp" ));

// Expression that makes a variability chart
makeVC = 
Expr(
	vc = CurrentDataTable() << Variability Chart(
								Y(:weight),
								X(TBD),
								Max Iter( 100 ),
								Std Dev Chart( 0 ),
								Show Range Bars( 0 ),
								Show Grand Median( 0 ),
								Std Dev Chart( 1 ),
								Points Jittered( 1 ),
								Show Box Plots( 1 )
								);
	);
	
makeBiv = Expr(Bivariate( Y( :height ), X( :weight ) ));

// Put the required 'x' values in 'makeVC'
mylist = {"sex" , "age"};
SubstituteInto(makeVC, Expr(TBD), Eval(myList));

newexpr = expr(tbd; tbd2);
substituteinto(newexpr, expr(tbd), nameexpr(makevc),
	expr(tbd2), nameexpr(makeBiv)
);
Jim
Article Labels

    There are no labels assigned to this post.