cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ressel
Level VI

Possible to preserve leading white space in column names for copied table scripts?

Problem: I run a script to load data from a database. I delete all formulas from the data table. I copy the table script using the red triangle menu. I paste the table script into a script window. I run the script. The table resulting from the table script has different column grouping and throws the columns around (see screenshot showing Columns panel from original table and table as created by table script side by side. See also files attached for reference).

Ressel_0-1666962417306.png

 

I initially suspected that this wass due to the table script not preserving leading whitespace in column names, but as the screenshot below shows, the leading whitespaces are indeed part of the table script, they are just not considered in the table re-created from the table script.

 

Ressel_0-1666962930002.png

 

Is there some way to really recreate the original data table, including white spaces in column names or is that generally a poor scripting strategy?

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Possible to preserve leading white space in column names for copied table scripts?

I have usually contacted jmp support with bugs. This post should be quite good example of the situation so remember to add link to this.

 

It is definitely (in my opinion) a good idea to rename the columns rather than try to manage some sort of weird workarounds. Those whitespaces could end up causing issues later anyway.

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Possible to preserve leading white space in column names for copied table scripts?

Even though I would never use leading whitespace in column name (I would also avoid most of special characters), in this case I would say it should work, as it seems to be valid column name in JMP.  I would say this is a bug with New Column.

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(1),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column(" A", Numeric, "Continuous", Format("Best", 12), Set Values([2]))
);
wait(1);
Column(dt, 2) << Set Name(" A");
wait(1);
dt << New Column("  A");

 

Only "quick" workaround that comes to my mind is to add << Set Name to New Table script, but I'm not sure if this would trigger before groupings are done

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(1),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column(" A", Numeric, "Continuous", Format("Best", 12), Set Values([2]), << Set Name(" A"))
);

so you would first have to get the script to clipboard and then get it as a text and modify that before running it.

 

This is very quick example which works with this one example:

Names Default To Here(1);

str = JSL Quote(dt = New Table("Untitled",
	Add Rows(1),
	New Column("A", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column(" A", Numeric, "Continuous", Format("Best", 12), Set Values([2]))
));

new_lines = {};
For Each({line}, Words(str, "\!N"),
	If(Starts With(Trim Whitespace(line), "New Column("),
		// get column name
		col_name = Regex(Trim Whitespace(line), "^New Column\(\!"(.+?)\!",\s", "\1");
		// add set name
		last_idx = Contains(line, ")", -1);
		new_line = Left(line, last_idx - 1) || ", << Set Name(\!"" || col_name ||"\!")),";
		Insert Into(new_lines, new_line);
	,
		Insert Into(new_lines, line);
	);
);

old_dt = Eval(Parse(str));
new_dt = Eval(Parse(Concat Items(new_lines, "\!N")));

-Jarmo
Ressel
Level VI

Re: Possible to preserve leading white space in column names for copied table scripts?

@jthi thanks. I was afraid that leading whitespace was bad practice. Any list this bug can or may be added to or reported?

Also, I think it is easier to rewrite my script to give different column names than to implement the workarounds suggested by you. (Labelled your response accidently as solution when I actually just tried to respond.) As always, thank you for your invaluable input and tireless efforts to educate other JMP users. This is extremely helpful.

jthi
Super User

Re: Possible to preserve leading white space in column names for copied table scripts?

I have usually contacted jmp support with bugs. This post should be quite good example of the situation so remember to add link to this.

 

It is definitely (in my opinion) a good idea to rename the columns rather than try to manage some sort of weird workarounds. Those whitespaces could end up causing issues later anyway.

-Jarmo