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
ionatx
Level II

Script to open Data Filter on currently-selected column, with Find and Regex enabled

Full disclosure: I'm not a coder and JSL gives me a particularly difficult time, however I feel that this portion of the script I am writing should be far easier than it has been. I use the Data Filter frequently, with "Find" and "Regular Expressions" enabled (see image), however there is no option to save these settings so they must be cumbersomely re-enabled every time I open the filter. What I would like is an embedded table script that:

 

1) opens the data filter

2) automatically adds the currently selected column (i.e. I'll selected a column, then launch the script)

3) Enable "Find"

4) Enable "Regular Expression"

image.png

 

Unfortunately the save script option only saves this:

Current Data Table() << Data Filter(
	Location( {630, 160} ),
	Conditional,
	Add Filter( columns( :name ), Display( :name, Size( 160, 225 ), List Display ) )
);

Find and Regex are not saved with the script . . .

 

But, here's the part that forced me to reach out for help, I cannot for the life of me figure out how to pass the currently-selected column's name to "columns()" and "Display()" functions.

I've tried many things, for example this:

Names Default to Here( 1 );

dt = Current Data Table( );

col_selected = dt << Get Selected Columns(string);

dt << Data Filter(
	Location( {630, 160} ),
	Conditional,
	Add Filter( columns( col_selected ), Display( col_selected, Size( 160, 225 ), List Display ) )
);

But I get an error:

 

"Specified Column not found in data table. in access or evaluation of 'columns' , columns( col_selected ) /*###*/"

 

Probably becasue col_selected is a list, but I can't figure out how to get just the name out of the one-item list. Really shouldn't be this hard.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Chris_Rodrigues
Level III

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

In order to pass a variable like col_selected to the Data Filter function, you have to use the Eval(Eval Expr(Expr())) construct.  JSL is so weird.  But here's what it looks like:

 

Names Default to Here( 1 );

dt = Current Data Table( );

col_selected = dt << Get Selected Columns(string);


Eval(
	Eval Expr(
		dt << Data Filter(
			Location( {630, 160} ),
			Conditional,
			Add Filter( columns( Expr(col_selected) ), Display( Expr(col_selected), Size( 160, 225 ), List Display ) )
		);
	)
);

For the Find and Regex options... I doubt that is even possible.  If you look at the Data Filter() documentation in the scripting guide there is no mention of those options.  I doubt the scripting interface has that level of granularity and those tickboxes can only be brought up interactively.  I may be wrong, though.  Someone else might chime in with a solution for that.

View solution in original post

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

That way is convoluted. It is not the only way that works, though. Expressions are powerful constructors but they are not always required. Keep in mind that the Columns() argument expects a column reference. That is all there is to it. It might be a literal value (column name), a value stored in a variable, or a value returned from a function.

 

Names Default to Here( 1 );

// open example data table
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// select a column (mimic result by interactive user)
dt << Go To( :age );

// identify selection
col = dt << Get Selected Columns( String );

// obtain column reference
col = Column( col[1] );

// launch data filter on selected column
df = dt << Data Filter(
	Add Filter( Columns( col ) )
);

View solution in original post

6 REPLIES 6
Chris_Rodrigues
Level III

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

In order to pass a variable like col_selected to the Data Filter function, you have to use the Eval(Eval Expr(Expr())) construct.  JSL is so weird.  But here's what it looks like:

 

Names Default to Here( 1 );

dt = Current Data Table( );

col_selected = dt << Get Selected Columns(string);


Eval(
	Eval Expr(
		dt << Data Filter(
			Location( {630, 160} ),
			Conditional,
			Add Filter( columns( Expr(col_selected) ), Display( Expr(col_selected), Size( 160, 225 ), List Display ) )
		);
	)
);

For the Find and Regex options... I doubt that is even possible.  If you look at the Data Filter() documentation in the scripting guide there is no mention of those options.  I doubt the scripting interface has that level of granularity and those tickboxes can only be brought up interactively.  I may be wrong, though.  Someone else might chime in with a solution for that.

Jeff_Perkinson
Community Manager Community Manager

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

@Chris_Rodrigues has a handle on how to get the variable to evaluate inside the Data Filter() message, and I can confirm that there is no JSL support for turning on the Find and Regex options.

 

If you feel that would be valuable, be sure to enter it in the JMP Wish List.

-Jeff
ionatx
Level II

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

@Chris_Rodriguesthat worked, I don't understand why it worked, but it worked.

 

@Jeff_Perkinsonthank you for the follow-up, and yes, I will.

Chris_Rodrigues
Level III

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

@ionatx I'm with you.  I struggled with this myself and eventually found the solution here on the forums.  My rough understanding is that you need to go through all this rigmarole to insert an expression into another expression. With your original code, col_selected was never being evaluated.  Data Filter() only saw the characters "col_selected" which it did not recognize as a column title, so it returned the error "Specified Column not found in data table".  So you enclose it inside of Expr() which signifies that it is an expression that needs to be evaluated.  Then enclose the entire thing inside of Eval Expr() to force evaluation of the things that are enclosed inside of Expr().  Then wrap an Eval() around the entire expression which essentially executes the expression to produce the desired output.  It all feels very convoluted, but that's how it works.

 

Would you like to know more?  https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-... 

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

That way is convoluted. It is not the only way that works, though. Expressions are powerful constructors but they are not always required. Keep in mind that the Columns() argument expects a column reference. That is all there is to it. It might be a literal value (column name), a value stored in a variable, or a value returned from a function.

 

Names Default to Here( 1 );

// open example data table
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// select a column (mimic result by interactive user)
dt << Go To( :age );

// identify selection
col = dt << Get Selected Columns( String );

// obtain column reference
col = Column( col[1] );

// launch data filter on selected column
df = dt << Data Filter(
	Add Filter( Columns( col ) )
);
ionatx
Level II

Re: Script to open Data Filter on currently-selected column, with Find and Regex enabled

Thanks @Mark_Bailey this also works although it filters only the first column if multiple are selected. However using your suggestion to obtain the column reference allowed me to create a FOR loop that does exactly what I want.

 

Names Default to Here( 1 );

dt = Current Data Table( );

list = dt << Get Selected Columns( );

obj = dt << Data Filter( );

For( i = 1, i <= N Items( list ), i++,
	obj << Add Filter( columns( Column( list[i] ) )
	)
);