How to store evaluated list in data table scriptHello,
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 ),
);
);Re: How to store evaluated list in data table scriptHere 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)
);Re: How to store evaluated list in data table scriptHi,
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 ?
Re: How to store evaluated list in data table scriptThe SubstitueInto does the job !!!
Thank a lot
Re: How to store evaluated list in data table scriptI can' t : the list is a result of a script
Re: How to store evaluated list in data table scriptJust 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 ),
);
);Re: How to store evaluated list in data table scriptI 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;