Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
JulieSAppel
Level IV

Column switcher & try function

Hi,

Is it possible to use the try function in a column switcher script? I´m creating a script where I add a column switcher fore a few chosen columns to a graph which works fine. However, sometimes a column will be missing which will make the script stop. Therefore, I´m trying to use the try function for each of the relevant columns (as I don´t want all columns in the column switcher) but I can´t make it work. 

 

dt << Column Switcher(
	Try( (:RER), Throw( "RER does not exist" ) ),
	Try( (:VO2), Throw( "VO2 does not exist" ) ),
	Try( :Name( "Drink-[ml]" ), Throw( "Drink-[ml] does not exist" ) )
);

 

Is it possible or is there a better way to do this?

Br Julie

 

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Column switcher & try function

Here is how I would do it

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );


// set desired list of columns to be in column switcher
desiredColList = {"Height", "Weight", "Zippy"};

// remove from list, columns that are not available
For( i = N Items( desiredColList ), i >= 1, i--,
	If( Try( Column( dt, desiredColList[i] ) << get name, "" ) == "",
		Remove From( desiredColList, i, 1 )
	)
);

// If columns are available, run the platform
If( N Items( desiredColList ) > 0,
	ow = oneway( x( :age ), y( :height ) );
	ow << Column Switcher( :height, desiredColList );
);
Jim
Highlighted

Re: Column switcher & try function

I would use the Try() function outside of the message. Build the message conditionally. Like this:

 

Names Default to Here( 1 );

dt = Open( "$SAMPLE_DATA/Fitness.jmp" );

gb = dt << Graph Builder(
	Size( 532, 456 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables( X( :Age ), Y( :Oxy ) ),
	Elements( Points( X, Y, Legend( 3 ) ) )
);

alt cols = List();
Try(
	Insert Into( alt cols, Column( dt, "Age" ) )
);
Try(
	Insert Into( alt cols, Column( dt, "Weight" ) )
);
Try(
	Insert Into( alt cols, Column( dt, "Runtime" ) )
);

col switcher expr = Expr( Column Switcher( :age ) );
Insert Into( col switcher expr, alt cols );

Eval(
	Insert(
		Expr( Send( gb ) ),
		Name Expr( col switcher expr )
	)
);
Learn it once, use it forever!
Article Labels

    There are no labels assigned to this post.