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
ivomdb
Level III

closing all data tables but leave one open for further analysis

Hi All

 

This is a follow up on the post:

 

https://community.jmp.com/t5/Discussions/JSL-How-to-close-data-tables-after-analysis/m-p/36739

 

However, I have encountered an error on my script while running JSL Debgger. 

DontClose = ("dt4");   // Example names of tables you want to leave
// Loop backwards through the list, so the table numbers do not change
For( i = N Table(), i >= 0, i--, 
	If( Contains( DontClose, Data Table( i ) << get name ),
		Continue(),
		Close( Data Table( i ), "No Save" )
	)
);

The script runs fine as in closes all the tables except dt4 but I get an error as shown on the file attached under the If statement. Does anyone have a clue what this is reffering to?  

The script runs fine and closes all the tables except dt4, however, I am having issues when extending the script after this point. I have a graph builder script to be launched after this point for the dt4 table but it does not do anything. SO I am wondering if this error here is stopping the script to continue to the next steps.

 

 

7 REPLIES 7
uday_guntupalli
Level VIII

Re: closing all data tables but leave one open for further analysis

@ivomdb,
          The error you see typically occurs if you are referring to a data table which JMP does not know exists or has no reference to access the table by. This happens mostly when the data table reference is lost or has been closed before it is being referenced. 

          One way to address this issue is by doing the following. 

          You should also try and make sure that the table is not being closed prematurely. 

DontClose = ("dt4");   // Example names of tables you want to leave
// Loop backwards through the list, so the table numbers do not change
For( i = N Table(), i >= 0, i--, 
        Current Data Table(Data Table(i)); // This should make the data table you are working with active and current 
	If( Contains( DontClose, Data Table( i ) << get name ),
		Continue();
                 ,
                // else 
		Close( Data Table( i ), "No Save" ); 
	)
);
Best
Uday
ivomdb
Level III

Re: closing all data tables but leave one open for further analysis

Hi Uday,

 

I have changed this but still get the same error under JSL Debugger. 

msharp
Super User (Alumni)

Re: closing all data tables but leave one open for further analysis

Your tables could be linked tables. See below example.  That or there's an error with your script and your referencing the wrong table by accident.  This is likely since you are looking for tables by name.

 

Names Default To Here( 1 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = dt1 << Summary(
	Group( :height ),
	Freq( "None" ),
	Weight( "None" )
);
close(dt1, "nosave"); //closes both dt1 and dt2 since dt2 is dependant on dt1

 

Either way, the code above is a poor way to handle closing tables.  First, you will close tables not related to your script, potentially making users mad that you closed the other things they were working on.  Second, leaving tables you don't need till the end to close is an inefficient use of memory.  It would be a better practice/pattern to close tables right after use instead of waiting till the end of the script.  If the tables are needed for the entire script, then I would recommend keeping track of the tables in a list so you only close the ones related to your script.

Phil_Kay
Staff

Re: closing all data tables but leave one open for further analysis

Is "dt4" the actual name of your table? It sounds more likely that it is the variable name that you have defined for the table in your script? I think your script is looking for the table name, i.e. what you see at the top of the JMP table, e.g. "Big Class":Table names example.png

 

 

This is a simple example (from the scripting index) of the Get Name() function that is used in your script:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
n = dt << Get Name();
Show( n );

  

BTW,  I could be wrong about this being the cause of your problem!

msharp
Super User (Alumni)

Re: closing all data tables but leave one open for further analysis

Phil I was thinking the same thing.  It's important to note that table names can't be duplicates, so if you try and create a new table names "dt4" and there is already a "dt4" table, JMP will name it "dt4 2".  Table names are not likely to be what you expect, which is another reason I feel the code above is a poor way to solve the problem at hand.

 

I just looked at the post linked in the original post.  Uday's code is much more production ready.  Unfortunately, the OP is using txnelson's simplification, which is just that a simplification and is where he's having all his issues.

ivomdb
Level III

Re: closing all data tables but leave one open for further analysis

Thanks for the advice. I have changed the approach and now I close the data tables earlier on the script. The script is actually faster now. Thanks

vince_faller
Super User (Alumni)

Re: closing all data tables but leave one open for further analysis

it's because you're >= 0.  There is no data table 0

either make it >= 1 or >0

 

DontClose = ("dt4");   // Example names of tables you want to leave
// Loop backwards through the list, so the table numbers do not change
For( i = N Table(), i >= 1, i--, 
	If( Contains( DontClose, Data Table( i ) << get name ),
		Continue(),
		Close( Data Table( i ), "No Save" )
	)
);
Vince Faller - Predictum