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
yvesprairie
Level IV

saving script to data table issue

HI all,

 

I have written a script (a few hundred lines) that 1)  opens an existing data table, 2) does a whole bunch of calculations and then 3) spits out a new data table with results from these calculations. Because I am continually improving the script, I want to make sure that I know which exact version of the script was used to create the new output data table and so thought of saving the whole script to the data table. I tried using NewDt<<save script to data table but this will only save as a script the line that created the NewDt, not the full script. Ideally I would like to save not only the script but also the original data table from which the NewDt was created. Any suggestions?

 

Regards and thanks, Yves 

6 REPLIES 6
txnelson
Super User

Re: saving script to data table issue

Here is a simple script that will show you one way to do this

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

biv = dt << bivariate( x( :height ), y( :weight ) );
theScript = Char( biv << get script );

Eval( Parse( "\[dt<<new script("Saved Script",]\" || theScript || ");" ) );
Jim
yvesprairie
Level IV

Re: saving script to data table issue

Thanks Jim but I don't think that it solves my problem. My issue is more like the following:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
m = dt << Get All Columns As Matrix();

Several lines of matrix algebra with the columns of m producing various vectors y1, y2, y3

dt2=as table(y1, y2, y3);

I want to entire script above to be saved to dt2. Thanks again, Yves

 

txnelson
Super User

Re: saving script to data table issue

So the question is, where does the script elements come from that you need to put together to build the literal string I called, "theScript". So where does what you call the "full script" come from?
Jim
yvesprairie
Level IV

Re: saving script to data table issue

That's the problem, the. script doesn't "come" from anywhere, it is simply all the lines I have written contained in my fictitious example. THis is what I can't figure out how to do! Thanks, Yves

txnelson
Super User

Re: saving script to data table issue

Here is a simple example of what you will have to do to create such a script.  Components that you will not be able to get from JMP, you will have to add into theScript as you build it.  Basically, you just concatenate it as you go.  Then when done, you add it to the data table.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt = current data table();

theScript = "\[dt = current data table(); ]\";
If( try( dt:ratio << get name,"") == "",
	dt<<new column("ratio", formula(:height/:weight))
);
theScript = theScript ||
"\[
	If( try( dt:ratio << get name,"") == "",
	dt<<new column("ratio", formula(:height/:weight))
	);
]\";


biv = dt << bivariate( x( :ratio), y(:weight ) );
theScript = theScript || Char( biv << get script );

Eval( Parse( "\[dt<<new script("Saved Script",]\" || theScript || ");" ) );

I have also used a method where I first build the entire script as a literal string, and then save it as a script.  Then I turn around and run the saved script, which then gives the results.

theScript = "\[
	dt = current data table();
	dt << bivariate( x(:weight), y(:height));
]\";
Eval( Parse( "\[dt<<new script("Saved Script2",]\" || theScript || ");" ) );
dt << run script("Saved Script2");
Jim
yvesprairie
Level IV

Re: saving script to data table issue

Many thanks I will try that! Your help much appreciated. Yves