I'm trying to insert a column name into a fit model expression. For that I need to escape strange characters in column names to do that we use the :"name"n convention. So how do I go from a string column name to this format?
colListY = {"Plating Thickness (m\!"\!")"};
//This doesn't work
newcolumnref = eval insert("\[:"^colListY[1]^"n]\");
//Looking for this end result
:"Plating Thickness (m\!"\!")"nWhich I can then insert anywhere, for example:
insert into(expr(Y()), newcolumnref);Anybody know of a robust way to do this?
Can you elaborate on the "does not work" part? I tried versions back to JMP 15 and the following seems to work. Maybe I'm missing part of the issue.
Data Table( "Big Class" ):weight << Set Name( "weight\!"\!"" );
Fit Model(
Y( Column( "weight\!"\!"" ) ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Run()
);
Just for giggles, I took the code back to JMP 11.2.1 and it works great.
@XanGregg Now that I'm testing it with your code it works here as well. Let me investigate and see if I can share the failing example more completely...
After carefull testing and going back through a few of my scripts I have not been able to make it fail again. Thanks for checking!
@XanGregg Column formulas don't work this way and the special quoting methods does work:
colListY = {"Plating Thickness (m\!"\!")"};
dt = Open( "$sample_data/big class.jmp" );
dt:age << setname( colListY[1] );
eval(eval expr(dt << New Column( "test",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 2 ),
Formula( expr(column(colListY[1])) - :height ),
Set Display Width( 78 )
)));It produces a function column in which the formula is:
Column( "Plating Thickness (m\!"\!")" ) - /*###*/:height/*###*/which does not evaluate.
This does:
WrapColumns = Function({ColName},{default local},
ReturnList = {};
If(is list(ColName),
For(i=1, i<=n items(ColName), i++,
insert into(ReturnList, parse(":" || Log Capture( Print( ColName[i] ) ) || "n"))
);
,
insert into(ReturnList, parse(":" || Log Capture( Print( ColName ) ) || "n"))
);
Return(ReturnList);
);
eval(eval expr(dt << New Column( "test2",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 2 ),
Formula( expr(WrapColumns(colListY)[1]) - :height ),
Set Display Width( 78 )
)));Do you know a way to fix this with the column() system?
(without trying it, so might be wrong)
Formula( column(expr(colListY[1])) - :height ),I think you want the expr inside the column. That way the column function is evaluated later, using the string captured earlier.
That results in a column formula error for me
colListY = {"Plating Thickness (m\!"\!")"};
dt = Open( "$sample_data/big class.jmp" );
dt:age << setname( colListY[1] );
Eval(
Eval Expr(
dt << New Column( "test",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 2 ),
Formula( Column( Expr( colListY[1] ) )[] ),
Set Display Width( 78 )
)
)
);The empty [ ] tells JMP to evaluate the column for the current row.
Building column formulas like this probably hides the underlying column dependencies from JMP's formula evaluator; see discussion. If you have formula columns depending on other formula columns, JMP may not be able to peer into this indirection to figure out what to evaluate first.
This is a great question!
This is a great question!