发布日期: 04/13/2021

Open a Data Table

Use the Open() function to open a data table.

To simply open a data table without returning a reference to it:

Open( "$SAMPLE_DATA/Big Class.jmp" ); // open the data table

To open a data table and retain a reference to it:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" ); // open and store a reference

The path to the data table can be a quoted literal path (absolute or relative) or an unquoted expression that yields a pathname. Relative paths are interpreted relative to the location of the .jsl file (for a saved script). For unsaved scripts, the path is relative to your primary partition (Windows) or your <username>/Documents folder (macOS).

Open( "../My Data/Repairs.jmp" ); // relative path on Windows and macOS
Open( "::My Data:Repairs.jmp" ); // relative path on macOS
Open( "C:/My Data/Repairs.jmp" ); // absolute path

JMP provides shortcuts (path variables) to directories or files. Instead of entering the entire path to the directory or file, you include a path variable in the Open() expression. For example, JMP sample scripts typically use the $SAMPLE_DATA path variable to open files in the Samples/Data folder. For more information about path variables, see Path Variables in the Types of Data.

If you do not want to specify the entire path every time you open a data table, define a filepath string and concatenate the path with the filename:

myPath = "C:/My Data/Store25/Maintenance/Expenses/";
Open( myPath || "Repairs.jmp" );

Upon opening a data table, JMP stores the data table in memory. This means that if a script attempts to open a data table that is already open, the opened version appears. JMP does not read the version that is saved on your computer.

Test for an Open Data Table

In a script that depends on an opened data table, you can test to see whether the table is open using Is Empty() or Is Scriptable(). In the following example, the script performs a Bivariate analysis on Big Class.jmp and then closes the data table. Before proceeding to the Oneway analysis later in the script, Is Scriptable() tests for the open data table. If 1 (true) is returned, the table opens, and the script continues.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
obj = dt << Bivariate( Y( :height ), X( :age ), Fit Line );
Close( dt );
If( Not( Is Scriptable( dt ) ),
	dt = Open( "$SAMPLE_DATA/Big Class.jmp" ),
);
obj = dt << Oneway( Y( :height ), X( :age ), Means( 1 ), Mean Diamonds( 1 ) );

You might want to see if the data table is open and then close it to discard any changes before running another script on the data table. To test for and close Big Class.jmp, run the following script:

Try( Close( Data Table( "Big Class" ) ) );

Prompt Users to Open a Data Table

You can use an If() expression to prompt a user to open a data table, if no open data table is found. And if they do not select a table, the script should end. The following script shows an example:

dt = Current Data Table();
If( Is Empty( dt ),
	Try( dt = Open(), Throw( "No data table found" ) )
);

The user is prompted to open a data table. If the user clicks Cancel instead of opening a data table, an error appears in the log.

Show Only Specific Columns

To open a data table and show only a specific set of columns, identify those columns in the Open() expression. This is particularly helpful with a large data table in which only a few columns are necessary.

The following example opens Big Class.jmp and includes only the age, height, and weight columns.

dt = Open( "$SAMPLE_DATA/Big Class.jmp", Select Columns( "age", "height", "weight" ) );

You can also specify the columns to leave out of the open data table:

dt = Open( "$SAMPLE_DATA/Big Class.jmp", Ignore Columns( "name", "sex" ) );
需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).