BookmarkSubscribe
Choose Language Hide Translation Bar
john_madden
Community Trekker

Move Selected Columns() with list parameter

If I have a table with five columns:

 

Column 5Column 3Column 2Column 1Column 4
datadatadatadatadata

 

and I execute this:

dt = Current Data Table();
dt << Move Selected Columns({"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"}, To first)

then I get this:

Column 1Column 2Column 3Column 4Column 5
datadatadatadata

data

 

But if I execute this:

dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
dt << Move Selected Columns( list, To first); 

it fails with an "Unrecognized key word" error.

 

I need to be able to parameterize the column list, as in the second version. How can I make something like the second version work? 

0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions
pmroz
Super User

Re: Move Selected Columns() with list parameter

I tried various flavors of as list(), listeval(), expr, evalexpr(), etc. to no avail.  Had to resort to eval(parse()):

dt = current data table();

alist = {"Column 4", "Column 3", "Column 2", "Column 1"};
clist = char(alist);

col_expr = evalinsert("dt << move selected columns(^clist^, to first)");

eval(parse(col_expr));
Highlighted
gzmorgan0
Super User

Re: Move Selected Columns() with list parameter

This is just an alternate method, and FYI.

 

You can also do this with expressions.  Eval Expr() replaces each Expr() with its value (name expression), and the external Eval() function, executes the command.

 

dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
Eval( Eval Expr(dt << Move Selected Columns( Expr(list), To first)) ); 
4 REPLIES 4
pmroz
Super User

Re: Move Selected Columns() with list parameter

I tried various flavors of as list(), listeval(), expr, evalexpr(), etc. to no avail.  Had to resort to eval(parse()):

dt = current data table();

alist = {"Column 4", "Column 3", "Column 2", "Column 1"};
clist = char(alist);

col_expr = evalinsert("dt << move selected columns(^clist^, to first)");

eval(parse(col_expr));
john_madden
Community Trekker

Re: Move Selected Columns() with list parameter

Thanks, that works for me!
0 Kudos
Highlighted
gzmorgan0
Super User

Re: Move Selected Columns() with list parameter

This is just an alternate method, and FYI.

 

You can also do this with expressions.  Eval Expr() replaces each Expr() with its value (name expression), and the external Eval() function, executes the command.

 

dt= Current Data Table();
list = {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"};
Eval( Eval Expr(dt << Move Selected Columns( Expr(list), To first)) ); 

Re: Move Selected Columns() with list parameter

I'm glad to hear a workaround has been found. In the meantime, we reported this issue to development, and JMP 15 (available later this year) has been updated so that the evaluation will happen automatically. Thanks!

0 Kudos