dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Script( "Bivariate Example", Bivariate( Y( :weight), X( :height ) ) );
dt << Get Table Variable( "Bivariate Example" );
// returns Bivariate( Y( weight ), X( height ) )
dt << Run Script( "Bivariate Example" )
dt << Set Property( "Bivariate Example", Bivariate( Y( :weight ), X( :height ), Fit Line ) ); // includes Fit Line in the Bivariate Example script
Suppose you want a text representation of a data table, perhaps to e-mail to a colleague or to use as part of a script. You can obtain a script that reconstructs the information in a data table with Get Script. The following example opens Big Class.jmp and prints the data, table variables, and column properties to the log. A portion of the output is shown here:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Get Script;
New Table( "Big Class",
Add Rows( 40 ),
New Script(
["en" => "Distribution",...],
Distribution(
Continuous Distribution( Column( :weight ) ),
Nominal Distribution( Column( :age ) )
) ),
The table script named On Open or OnOpen can be automatically run when the data table opens. Users are prompted to run the script by default. Their choice is remembered each time they open the data table in the current JMP session.
To create an On Open script, perform one of the following actions:
•
|
Create the script using the Save Script > To Data Table option, and then double-click the property name and change the name to On Open.
|
•
|
Store the script using a New Script message.
|
In this example, you create an OnOpen script in Big Class.jmp.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Script(
"OnOpen", // create the script
sortedDt = dt << Sort( By( :name ), Output Table Name( "Sorted Big Class" ) ) // sort the data and put it in a new data table
);
The JMP preference called Evaluate OnOpen Scripts determines when the script runs. By default, the user is prompted to run the script. You can set the preference to always run the On Open script or to prevent it from running:
Preference( Evaluate OnOpen Scripts( "always" ) );
Preference( Evaluate OnOpen Scripts( "never" ) );
Preference( Evaluate OnOpen Scripts( "prompt" ) ); // default setting
On Open scripts that execute other programs are never run. As a safety precaution, you might consider suppressing automatic execution when opening data tables that you receive from others.
Note: When you create a new data table in a script and include the On Open() function, On Open() is called before the data table is created, not after.