Variable column group name for 'Group Columns()'Hi all,
I'm trying to select columns based on a list of strings, and dump the columns into a group also based on the list.
Here's the code I'm using:
dt = Current Data Table();<BR />// phase names by which we want to group
groupnames = {"Centering", "Dwell", "Capture", "Locking"};
// all column names in the table
allcols = dt << Get Column Names();
For( i = 1, i <= N Items( groupnames ), i++,
curgroup = {};
dt << Clear Column Selection;
// get all cols with the phase name
For( j = 1, j <= N Items( allcols ), j++,
If( Contains( allcols[j], groupnames[i] ),
As Column( allcols[j] ) << Set Selected( 1 );
//Insert Into(curgroup, allcols[j]);
);
);
// make a new group from these columns
//dt << Group Columns(char(groupnames[i]), curgroup);
dt << Group Columns( groupnames[i] );
);I get the error "JMP cannot determine the columns to be grouped from the given script."
If I change the last line to something like dt << Group Columns ( "fixed string") it will work (but they'll all be in the same group). I'm not sure what I'm doing wrong. groupnames[i] should be a string (right?), which is the expected input for Group Columns().
Thanks,
Kristo
Re: Variable column group name for 'Group Columns()'Thanks again. I was just looking in the html documentation, not the books.
Re: Variable column group name for 'Group Columns()'Here is how to get to the documentation on the escape characters. Go to
Help==>Books==>Scripting Guide
and then do a page search for
\!
It will take you directly to the table of escape characters
Re: Variable column group name for 'Group Columns()'Eval Insert() evaluates variables within a string. The variables in the string are wrapped in “^” characters. Parse() turns a string into an expression. Eval() evaluates the expression.
So basically you build the expression as a string with the variable values resolved within the string, you parse the string into an expression, and evaluate the expression.
Re: Variable column group name for 'Group Columns()'Thanks, that did it! Any pointer to documentation on the what the different escape sequences are for? The "help" for Parse() is not so useful.
Re: Variable column group name for 'Group Columns()'Sometimes, JMP is weird about evaluating variables that should resolve to the expected argument type. I generally try not to do this, but you can usually get around these issues with a Eval-Parse-Eval Insert sequence. This always feels like a bit of a hack, but it's like duct tape with JSL.
dt = Current Data Table();// phase names by which we want to group
groupnames = {"Centering", "Dwell", "Capture", "Locking"};
// all column names in the table
allcols = dt << Get Column Names();
For( i = 1, i <= N Items( groupnames ), i++,
curgroup = {};
// get all cols with the phase name
For( j = 1, j <= N Items( allcols ), j++,
If( Contains( allcols[j], groupnames[i] ) > 0,
Insert Into(curgroup, allcols[j]);
);
);
// make a new group from these columns
Eval(Parse(Eval Insert("\[dt << Group Columns( "^groupnames[i]^", curgroup )]\")));
);