cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
pcarroll1
Level IV

Inconsistent acceptable syntax

AllCols = dt << Get Column Names();
AllColNames = dt << Get Column Names(string);
for(i=3, i<=n items(AllCols), i++, 
	colcol = AllCols[i];
	cname = AllColNames[i];
	nnm1 = Col Number(colcol);
	Fstr = "num(:\!""||cname||"\!"n)";
	Fexpr = parse(Fstr);
	newcol = dt << new column("Temp", numeric, formula(eval(evalexpr(Fexpr))));
	nnm2 = Col Number(newcol);
	if(nnm2 == nnm1, 
		newcol << delete formula();
		dt << Delete Columns(colcol);
		newcol << set name(cname),  //else
		dt << Delete Columns(newcol);
	);
);

I am using JMP18 on Windows.  When I write code that I want to use often, I like to make a toolbar button for it.  But sometimes I find that code that is acceptable to run from an open script window is not acceptable when run from a toolbar icon.  Here is an example, where I am looping through columns and changing them from character to numeric if all entries are numeric.  When running from a toolbar the objection is for the line:

newcol = dt << new column("Temp", numeric, formula(eval(evalexpr(Fexpr))));

This syntax is acceptable when I run from a script window!

Why would the jsl interpreter be different in each situation?

What syntax for this would be universally acceptable?

For very large datasets and columns this can be slow.  Is there a better way to do this?  

6 REPLIES 6
Craige_Hales
Super User

Re: Inconsistent acceptable syntax

What error message did you get? I think the script window has a current data table but the toolbar script may not. Maybe just adding

currentDatatable(dt);

at the start of the script would be enough.

You could 

print(currentDatatable());

at the start of the script to find out what the toolbar script knows.

 

 

Craige
pcarroll1
Level IV

Re: Inconsistent acceptable syntax

Thanks Craige.

The error message is:

Name Unresolved: 2PCS_X(um) at row 1 in access or evaluation of '2PCS_X(um)' , "2PCS_X(um)"n /*###*/

"2PCS_X(um)" is the name of the first column to be evaluated.

So the expression for the first column is supposed to be:

newcol = dtTOSA << new column("Temp", numeric, formula(Num( :"2PCS_X(um)"n )));

pcarroll1
Level IV

Re: Inconsistent acceptable syntax

Also, in the actual script I don't use dt as a variable.  I use a much more descriptive variable, like dtTOSA. (see above)  Everytime I want to address a particular data table I always explicitly state it to avoid confusion, as I did in this statement.  I don't see how the interpreter could think I'm referring to a different table.  

jthi
Super User

Re: Inconsistent acceptable syntax

Toolbars might be adding Names Default To Here(1) (which I say you should always have) to your script

jthi_0-1731602218857.png

which can then potentially show some errors which wouldn't be visible if everything is in global scope (but still they are usually errors). I build my formulas using either Eval(EvalExpr()) or Eval(Substitute())

Eval(EvalExpr(
	newcol = dt << New Column("Temp", numeric, formula(Num(Expr(NameExpr(AsColumn(dt, i))))));
));

For large datasets you might have to consider sampling for something like this.There are also non-formula solutions which might be faster but it might also depend on your data.

 

For some reason I haven't published this to JMP community (or atleast I couldn't find it), Character Columns to Numeric (github.com) , you can take a look at the code to see how I have performed this task from https://github.com/jthi-jmp-tools/character-columns-to-numeric/blob/main/bin/bin/character_columns_t.... I have since redone this script and if I remember correctly I do use a bit different method nowadays.

-Jarmo
hogi
Level XII

Re: Inconsistent acceptable syntax

toolbar icons know the  current data table():
The problem is rather the inverse one.

Please  define "dt=current data table()" before the 

dt << Get Column Names();

 

 

Craige_Hales
Super User

Re: Inconsistent acceptable syntax

Maybe, but the error message suggests JMP is not looking in the right place for "2PCS_X(um)"n. I'm not sure what context the toolbar script can use.

Craige