Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to store evaluated list in data table script

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 19, 2018 12:21 AM
(2408 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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;
```

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 ),
);
);
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to store evaluated list in data table script

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to store evaluated list in data table script

The SubstitueInto does the job !!!

Thank a lot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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