cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Choose Language Hide Translation Bar
matlag
Level III

Can't "evaluate" an expression

Hi all,

 

I'm once again struggling with a script...

 

This one builds an expression. It looks ok.

I can even copy and paste it from the log file back to the script window, and if I do so, it executes correctly with expected output.

But I tried Eval(), Eval Expr(), Eval(Eval Expr()), Eval(Parse())... well that last one with even less hope than the others, but bottom line is... I just can't make it work!

Names Default To Here( 1 );
ParamsList = {
	{"P1", "Parameter 1"},
	{"P2", "Parameter 2"}
};

analysis = Expr(Analysis Column());

For (i=1, i<= Length(ParamsList), i++,
	Insert Into(
		analysis,
		Substitute(
			Expr(Transform Column("__Desc__", Formula(__Parameter__))),
			"__Desc__", ParamsList[i][2]||" Median",
			Expr(__Parameter__), Parse(":"||ParamsList[i][1]||"_Q50")
		)
	);
);

addRowExpr = Expr(Row Table());
Insert Into(addRowExpr, Eval Expr(analysis));
Insert Into(addRowExpr, Expr(Statistics(Median)));

addTabExpr = Expr(Add Table(Column Table(Grouping Columns(:Source))));
Insert Into(addTabExpr, Eval Expr(addRowExpr));

tabExpr = Expr(Tabulate(Set Format(Uniform Format(10,2))));
Insert Into(tabExpr, Eval Expr(addTabExpr));

show(tabExpr);

dtParams = Eval(Eval Expr(tabExpr));

I attach a "Test.jmp" file on which you can try.

 

The output of the "show" command is:

tabExpr = Tabulate(Set Format(Uniform Format(10, 2)), Add Table(Column Table(Grouping Columns(:Source)), Row Table(Analysis Column(Transform Column("Parameter 1 Median", Formula(:P1_Q50)), Transform Column("Parameter 2 Median", Formula(:P2_Q50))), Statistics(Median))));

And as said: if I copy-paste it back to the script window to execute that output, I get what I want!

 

So, how do I "evaluate" that expression?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Can't "evaluate" an expression

Using my "Morning Brain" I have come up with:

eval(parse(char(evalexpr(tabexpr))))

which will allow the expression that has been built to execute.

 

I agree with Ian, the code should work as developed, and I suggest you post the issue to:

     support@jmp.com

Jim

View solution in original post

8 REPLIES 8

Re: Can't "evaluate" an expression

Just running "tabExpr" will evaluate the expression.

tabulateObject = tabExpr;

 

Justin
matlag
Level III

Re: Can't "evaluate" an expression

Hi Justin,

It doesn't work here. I'm on JMP 12.1 if that helps.
What it does is creating a tabulate, but it does not populate the content. I get columns A and B.
I have a single row and the count of A and B.
txnelson
Super User

Re: Can't "evaluate" an expression

What is your expected output?  I see a lot of things being generated and placed into lists, but I don't see anything being done with those things.  

Jim
matlag
Level III

Re: Can't "evaluate" an expression

Argh!

I understand the problem you have, I uploaded Test.jmp before saving a change.

Here is the right version.

 

Expected output (by copying in the log the result of the show())

2017-06-08 16_02_54-Test - Tabulate - JMP Pro.png

 

The reasons I'm going with a script like this are:

-The list of parameters in the real application is much longer

-The paremeters will change depending on my input data, but they're always documented.

txnelson
Super User

Re: Can't "evaluate" an expression

It is certainly strange that the code does not appear to be fully executable in open code.  The only way that I was able to do it, was to convert your expresion tabExpr into a literal string, and to run it with Eval(Parse().

eval(parse("Tabulate(
	Set Format( Uniform Format( 10, 2 ) ),
	Add Table(
		Column Table( Grouping Columns( :Source ) ),
		Row Table(
			Analysis Column(
				Transform Column(\!"Parameter 1 Median\!", Ordinal, Formula( :P1_Q50 ) ),
				Transform Column(\!"Parameter 2 Median\!", Ordinal, Formula( :P2_Q50 ) )
			),
			Statistics( Median )
		)
	)
);"))

Maybe one of the other community members have an idea

Jim
ian_jmp
Staff

Re: Can't "evaluate" an expression

This is indeed strange, and I haven't added much other than to put the code in one place. I suspect it's related to the use of virtual columns, but needs more investigation.

Names Default To Here( 1 );
ClearLog();

dt = New Table( "Test",
					Add Rows( 5 ),
					New Column( "P1_Q50",
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Set Values( [32.6, 54.8, 48.9, 28, 51.4] )
					),
					New Column( "P2_Q50",
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Set Values( [9, 7, 8, 6, 12] )
					),
					New Column( "Source",
						Character( 1 ),
						"Nominal",
						Set Values( {"A", "B", "B", "A", "B"} )
					)
				);

ParamsList = {
	{"P1", "Parameter 1"},
	{"P2", "Parameter 2"}
};

analysis = Expr(Analysis Column());

For (i=1, i<= Length(ParamsList), i++,
	Insert Into(
		analysis,
		Substitute(
			Expr(Transform Column("__Desc__", Formula(__Parameter__))),
			"__Desc__", ParamsList[i][2]||" Median",
			Expr(__Parameter__), Parse(":"||ParamsList[i][1]||"_Q50")
		)
	);
);

addRowExpr = Expr(Row Table());
Insert Into(addRowExpr, Eval Expr(analysis));
Insert Into(addRowExpr, Expr(Statistics(Median)));

addTabExpr = Expr(Add Table(Column Table(Grouping Columns(:Source))));
Insert Into(addTabExpr, Eval Expr(addRowExpr));

tabExpr = Expr(Tabulate(Set Format(Uniform Format(10,2))));
Insert Into(tabExpr, Eval Expr(addTabExpr));

show(tabExpr);
NewWindow("tabExpr", tabExpr);
NewWindow("Eval(Parse(Char(NameExpr(tabExpr))))", Eval(Parse(Char(NameExpr(tabExpr)))));
txnelson
Super User

Re: Can't "evaluate" an expression

Using my "Morning Brain" I have come up with:

eval(parse(char(evalexpr(tabexpr))))

which will allow the expression that has been built to execute.

 

I agree with Ian, the code should work as developed, and I suggest you post the issue to:

     support@jmp.com

Jim
matlag
Level III

Re: Can't "evaluate" an expression

Hi Jim,

Your solution works indeed! Thanks very much.
I'm contacting support.