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
jthi
Super User

Accessing .jmp file row/col count and notes without opening file

This information can be accessed through JMP Open file at least on Windows:

jthi_0-1615283854316.png

 

Wondering if it possible to access these through scripting without opening JMP datatable (Open Data File Options )?

 

Column names can be accessed with

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp", "Column Names Only");

 

 

 

-Jarmo
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Accessing .jmp file row/col count and notes without opening file

I attended Meet the Developers session today in the Discovery Summit to ask about this. It seems that a solution like the one I posted earlier (get column names, N  Items() those for column count, open datatable with one column as private and N Rows() for row count) is currently the fastest way to do this. They took a note so maybe in future it will be possible without opening even private datatables or JMP will provide functionalities to do this.

 

Below is the script in function format. They suggested to add Close for the dt_temp. This script might need Wait(0); here and there, but as it did work without them I haven't added any.

Names Default To Here(1);
//https://community.jmp.com/t5/Discussions/Accessing-jmp-file-row-col-count-and-notes-without-opening-file/td-p/366316

//Function to get column count, rowcount, table notes and column names to associative array
getTableInfo = function({path_to_table}, {Default Local},
	//Check that file exists
	If(!File Exists(path_to_table),
		return(Associative Array({"error"}, {"File not found"}));
	);
	
	//Initialize associative array
	retVal = Associative Array(
		{"name", "rowCount", "columnCount", "notes", "columnNames"},
		{"", 0, 0, "", {}}
	);
	//Open datatable as columns only list
	colNames = Open(path_to_table, "Column Names Only");
	//Check that table has atleast one column
	If(N Items(colNames) > 0,
		retVal["columnNames"] = colNames;
		retVal["columnCount"] = N Items(colNames);
		dt_temp = Open(path_to_table, Select Columns([1]), Private);
		retVal["name"] = dt_temp << get name();
		retVal["rowCount"]  = N Rows(dt_temp);
	);
	//Get notes from "Notes" table variable
	retVal["notes"] = dt_temp << Get Table Variable("Notes");
	Close(dt_temp, no save);
	return(retVal);
);

//Examples with tables from $SAMPLE_DATA
aa_probe = getTableInfo("$SAMPLE_DATA/Probe.jmp");
Show(aa_probe["name"],aa_probe["rowCount"], aa_probe["columnCount"], aa_probe["notes"]);
Show(getTableInfo("$SAMPLE_DATA/Alcohol.jmp"));
Show(getTableInfo("$SAMPLE_DATA/Alcohol.jmpmissing"));
-Jarmo

View solution in original post

5 REPLIES 5
SDF1
Super User

Re: Accessing .jmp file row/col count and notes without opening file

Hi @jthi ,

 

  I do not know how to get that information from the open window dialogue in JMP, but you could do something like this:

Names Default to Here(1);
dt=open("$SAMPLE_DATA/Big Class.jmp", Invisible);
Show(Nrows(dt));
Show(NCols(dt));
Close(dt);

  It should return the following in the Log window or embedded log of the Scripting window:

N Rows(dt) = 40;
N Cols(dt) = 5;

 

  The "Invisible" in the open command will not make the data table come up to the front and sort of hides it in the background. You could even do a Show Properties(dt) command and get a much more extensive list of information on the data table.

 

  I know it's not exactly what you want, but it can do the job, I think.

 

DS

txnelson
Super User

Re: Accessing .jmp file row/col count and notes without opening file

I would suggest specifying "Private" rather than "Invisible". It doesn't make JMP work as hard, since it doesn't have to create the display objects.
Jim
jthi
Super User

Re: Accessing .jmp file row/col count and notes without opening file

The way JMP shows it in Open Data File menu is way faster (maybe...). I have some tables which are quite wide, 60columns, and very tall, ~15million rows. Opening these is fairly slow. I can get column count by opening it only as column names and maybe row count by opening datatable only as single column but all rows, but I think this will still be slower. Of course it could be possible that JMP is doing something like this behind the scenes?

 

I could maybe implement something like this:

Names Default To Here(1);
dtPath = "$SAMPLE_DATA/Probe.jmp";
//dtPath = "$SAMPLE_DATA/Alcohol.jmp"; //table with notes
colNames = Open(dtPath, "Column Names Only");
colCount = N Items(colNames);
dt_temp = Open(dtPath, Select Columns([1]), Private);
notesTableVar = dt_temp << Get Table Variable("Notes");
rowCount = N Rows(dt_temp);
dt_temp = Empty();
Show(colCount, rowCount, notesTableVar);
//Show(colNames);

Because Discovery Summit is currently going, maybe I hop in to one of the Meet-The-Developer sessions and ask this also there.

 

-Jarmo
jthi
Super User

Re: Accessing .jmp file row/col count and notes without opening file

I attended Meet the Developers session today in the Discovery Summit to ask about this. It seems that a solution like the one I posted earlier (get column names, N  Items() those for column count, open datatable with one column as private and N Rows() for row count) is currently the fastest way to do this. They took a note so maybe in future it will be possible without opening even private datatables or JMP will provide functionalities to do this.

 

Below is the script in function format. They suggested to add Close for the dt_temp. This script might need Wait(0); here and there, but as it did work without them I haven't added any.

Names Default To Here(1);
//https://community.jmp.com/t5/Discussions/Accessing-jmp-file-row-col-count-and-notes-without-opening-file/td-p/366316

//Function to get column count, rowcount, table notes and column names to associative array
getTableInfo = function({path_to_table}, {Default Local},
	//Check that file exists
	If(!File Exists(path_to_table),
		return(Associative Array({"error"}, {"File not found"}));
	);
	
	//Initialize associative array
	retVal = Associative Array(
		{"name", "rowCount", "columnCount", "notes", "columnNames"},
		{"", 0, 0, "", {}}
	);
	//Open datatable as columns only list
	colNames = Open(path_to_table, "Column Names Only");
	//Check that table has atleast one column
	If(N Items(colNames) > 0,
		retVal["columnNames"] = colNames;
		retVal["columnCount"] = N Items(colNames);
		dt_temp = Open(path_to_table, Select Columns([1]), Private);
		retVal["name"] = dt_temp << get name();
		retVal["rowCount"]  = N Rows(dt_temp);
	);
	//Get notes from "Notes" table variable
	retVal["notes"] = dt_temp << Get Table Variable("Notes");
	Close(dt_temp, no save);
	return(retVal);
);

//Examples with tables from $SAMPLE_DATA
aa_probe = getTableInfo("$SAMPLE_DATA/Probe.jmp");
Show(aa_probe["name"],aa_probe["rowCount"], aa_probe["columnCount"], aa_probe["notes"]);
Show(getTableInfo("$SAMPLE_DATA/Alcohol.jmp"));
Show(getTableInfo("$SAMPLE_DATA/Alcohol.jmpmissing"));
-Jarmo
Jeff_Perkinson
Community Manager Community Manager

Re: Accessing .jmp file row/col count and notes without opening file

Thanks for highlighting one of the benefits of attending Discovery Summit and Meet the Developers/Ask the Experts.

 

As a result of your conversation and this post in JMP 17 we'll be adding a JSL option to get the number of rows and columns in a data table, along with the names of the columns and the contents of the Notes property if it exists. Bravo!

-Jeff