it's me again. Another day, another question
So I made a nice long script that creates a new data table which contains some scripts. I use the New Script () function to do this.
dt<< New script ("myscript", // comments //beautiful indentation ( ( ( ( instructions) ) ) ) ) );
My issue is that when I check the script Inside the table dt, all comments are lost, as well as the layout, my personal style of indentation, empty lines, etc.
These scripts are intended for users who are not necesarily familiar with JSL, so I need to keep the comments and the original layout.
I was trying to do something like putting my scripts in a string and using Append() or Append Text() but was unsuccessful.
mystring = " \[ // all my // script ]\" ; myscript = dt<<New Script ("my script", //some instructions ); myscript << Append Text (mystring)
Unfortunately this did not work. Any ideas ? Some tricks using Expr/ Eval , etc maybe ?
JSL Quote() might help:
New Table( "formatted script", New Script( "my script", Eval( Parse(JSL Quote( // example x = 1; Print( :column 1, y ); ) ) ) ), New Column( "Column 1", Set Values(  ) ) )
Unfortunately, JMP is not designed to keep comments and formatting for scripts attached to the data table. This has been requested in the JMP Wish List: Preserve comments and whitespace in JSL code. Be sure to kudo that to indicate your support. I'll make sure the developers are aware of the desire.
I was affraid this would be the answer. However I feel there could be a DIY solution to bypass this...
For example, I tried putting all my script into an Expr () statement and it exported fine. Of course in the final script, everything is still between the brackets of the Expr.
But perhaps a text editing script could read this and delete the Expr and the brackets to have the original text ?
so my question is, is this possible? Can a script edit another script in this way ?
Or perhaps I could have my data table's scripts saved as separate .jsl files and then have the table automatically import them ?
Come on, there must be a way to do this
it looks like JMP scripts can't be edited by another script. I was trying to write my script in a script box Inside a window. But as far a s I can see, the contents of a script box cannot be saved to a data table.
It looks like this is not feasible after all.
A couple of half baked backup options though :
Any other ideas, insights ??
We ran into this issue in our JMP training courses about scripting. We imposed a particular style and format to make the code as clear as possible so we wanted to maintain it at all times. Our solution was to take advantage of the JMP journal that was created for each course. We added a button for each script that we provide in the course. The button script stores the formatted script as a character string in a script file and then opens or runs it. Here is a very simple example to illustrate what the journal button does:
script = "dt = Open( \!"$SAMPLE_DATA/Big Class.jmp\!" ); dist = dt << Distribution( Y( :weight, :height ) );"; Save Text File( "My Script.jsl", script ); Open( "My Script.jsl" );
This solution works well for our purpose in the training. I don't think it will help you, though.
The table scripts could run the scripts that are saved this way.
Include( "My Path/My Script.jsl" );
You can put the scripts anywhere (e.g., a single repository folder) and include the full path.
You said, "it looks like JMP scripts can't be edited by another script. I was trying to write my script in a script box Inside a window. But as far a s I can see, the contents of a script box cannot be saved to a data table."
It is possible. It might not be obvious. It requires scripting techniques that are not basic, though. Here is an example to illustrate how it might be done. It
Names Default to Here( 1 ); script window = New Window( "Script", << Modal, sb = Script Box( "print(\!"Hello\!");" ), H List Box( Button Box( "OK", s = sb << Get Lines ), Button Box( "Cancel" ) ) ); If( script window["Button"] == -1, Throw( "User cancelled" ); ); Print( s ); n = N Items( s ); script = s; For( line = 2, line <= n, line++, script ||= "\!n" || s[line]; ); Print( script ); Eval( Parse( script ) ); Eval( Substitute( Expr( Current Data Table() << New Script( "My Script", sss ) ), Expr( sss ), Parse( script ) ) );
However, the table script loses the formatting because the Parse() function discards it, just like the JSL interpreter. So this example does not solve your original problem.
Thanks for this piece of code, it is useful indeed.
So that solves one point : the content of a script window can be saved into a Script.
But, the first part still seems true "JMP scripts can't be edited by another script". The script you provided writes a new script every time with the New Script () function;
As far as I can see there is no way to refer to a script within a data table and that is the issue. What I mean is that there is no datatable: myscript or datatable<<edit script ("myscript").
all one can do is to copy scripts, and then past them in a new script. But, indeed that doesn't solve the issue as it transforms it into a JSL expression, deleting comments and formatting in the process.
I think it is time to admit there is currently no solution. It is in the JMP wishlist, so as @Jeff_Perkinson mentionned,
everyone interested please make sure to kudo Preserve-comments-and-whitespace-in-JSL-code-attached-to-data !!
You said, "As far as I can see there is no way to refer to a script within a data table and that is the issue. What I mean is that there is no datatable: myscript or datatable<<edit script ("myscript")." You can send this message to the data table, after running my example code above:
dt << Get Script( "My Script" );
Now I can use expression or character string functions to edit the script from the data table.
There are no labels assigned to this post.