turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Can't "evaluate" an expression

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 8:50 AM
(1268 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 9, 2017 2:35 AM
(2396 views)

Solution

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

8 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 10:29 AM
(1256 views)

Just running "tabExpr" will evaluate the expression.

`tabulateObject = tabExpr;`

Justin

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 10:34 AM
(1253 views)

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 12:30 PM
(1242 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 1:07 PM
(1237 views)

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())

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 8, 2017 3:00 PM
(1226 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 9, 2017 1:38 AM
(1212 views)

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)))));
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 9, 2017 2:35 AM
(2397 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 9, 2017 5:00 AM
(1194 views)

Hi Jim,

Your solution works indeed! Thanks very much.

I'm contacting support.

Your solution works indeed! Thanks very much.

I'm contacting support.