Hello,
I've built a script that performs data analysis but requires various user inputs to configure. There are cases where I want to perform a similar analysis later, but not need to re-enter all my settings. The main script already can read existing variables and auto-fill those fields, so if I have some way to save and import those default values, I'll be set. I want to be able to have multiple different configurations and not need to edit the script itself to make a new one.
One idea was to save a table with a column of variable names and a column of their values, but that didn't play well with different variable types (numbers, strings, lists).
A better-seeming idea is to save other .jsl files that contain the default settings for different use cases into a shared namespace, then run the relevant one before running my main script. I'd like to be able to create the configuration file from within my script, rather than manually making them.
I found this other post about saving new jsl files. https://community.jmp.com/t5/Discussions/how-do-you-create-a-new-script-file-from-jsl/td-p/34740
It seems like I should be able to set up a JSL quote, then substitute the current values of variables into that quote, but NameExpr isn't working for that. Strings are substituted without quote marks, lists just appear as List and numbers are ignored. Is there a slight change that would make this work, or a better way to accomplish the same goal?
Thanks!
names default to here (1);
//namespace for the shared variables
If( !Namespace Exists( "TestNS" ), New Namespace( "TestNS" ) );
//the variables I want to save for later
TestNS:a = 5;
TestNS:b = "text";
TestNS:c = {1,2,3,4};
TestNS:d = {"a","b","c","d"};
//set up script to save as JSL
script = JSL Quote(
TestNS:a = a_dv;
TestNS:b = b_dv;
TestNS:c = c_dv;
TestNS:d = d_dv;
);
//substitute the dummy values for the current values... this isn't working
substitute Into (script, expr(a_dv), nameexpr (TestNS:a));
substitute Into (script, expr(b_dv), nameexpr (TestNS:b));
substitute Into (script, expr(c_dv), nameexpr (TestNS:c));
substitute Into (script, expr(d_dv), nameexpr (TestNS:d));
show(script);
//save script for later use
Save Text File( "$downloads\MyScript.jsl", script );