BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Thierry_S

Contributor

Joined:

Apr 19, 2018

JSL script (rename columns) feedback: it works but I'm not sure why!

Hi JMP community,

 

After 2 days of learning, I have finally produced a JSL script that performs the column name change operation I was looking for. However, considering the rather laborious process to get to this result, I suspect that I may have used sub-optimal approaches. Therefore, I'm looking for ways to clean up this script.

 

Names Default To Here( 1 );
dt = Current Data Table();

src=.;
trg = .;

sfx = "";
pfx = "";

n = 0;
m = 0;

win = New Window (
	" WARNING ",
	<< Modal,
	Text Box (" It is recommended that you save your table before proceeding "),
	Button Box (
		"SAVE NOW",
		dt << Save("");
		),
	);

cd = Column Dialog(
		cl1 = ColList( "SOURCES", Min Col (1)),
		cl2 = ColList( "TARGETS", Min Col (1)),
		Line Up( 2,
			Text Box( "Prefix" ), ex = EditText( "P_" ),
			Text Box( "Suffix" ), ey = EditText( "_S" )
		),
		
);


src=cd[1];
srcx = right (src,length (src)); // I'm not sure how this works but without this the script fails
n = N items (srcx);

trg = cd[2];
trgx = right (trg,length (trg)); // I'm not sure how this works but without this the script fails
m = N items (trgx);

pfx = cd [4];
sfx = cd [6];

If (n == m, 
	
	st = "";
	For (i=1, i <= m, i++,
		
		scol = srcx [i] << Get Name;
		st = pfx || scol || sfx;
		trgx [i] << Set Name (st);
		
				
	);

,Stop());

Your feedback would be greatly appreciated.

 

Cheers,

 

TS

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ms

Super User

Joined:

Jun 23, 2011

Solution

Re: JSL script (rename columns) feedback: it works but I'm not sure why!

Great that you want to learn JSL. It's really useful! And it's not that hard to get started  if you have experience of working in JMP interactively. Much of the JSL syntax then seems logical and straightforward. However, there's of course some quirky things such as the list returned by Column Dialog(). 

 

I would probably used a non-modal New Window() as a control panel instead for this task.

Below is an attempt to simplify your script, still using Column Dialog. I use Eval List() to execute the some of the assignement expressions of the output of Column Dialog, which eliminates the need for extra variables. 

Names Default To Here(1);
dt = Current Data Table();

cd = Column Dialog(
    src=ColList("SOURCES", Min Col(1)),
    trg = ColList("TARGETS", Min Col(1)),
    Line Up(2,
        Text Box("Prefix"), pfx = EditText("P_"),
        Text Box("Suffix"), sfx = EditText("_S")
    )
);
Eval List(cd[[1 2 4 6]]); //Execute relevant assignments within list cd
Show(src, trg, pfx, sfx); // Just to confirm (can be deleted)

n = N Items(src);
m = N Items(trg);

For(i = 1, i <= Min(n, m), i++,
    trg[i] << Set Name(pfx || (src[i] << get name) || sfx)
);
2 REPLIES 2
Highlighted
ms

Super User

Joined:

Jun 23, 2011

Solution

Re: JSL script (rename columns) feedback: it works but I'm not sure why!

Great that you want to learn JSL. It's really useful! And it's not that hard to get started  if you have experience of working in JMP interactively. Much of the JSL syntax then seems logical and straightforward. However, there's of course some quirky things such as the list returned by Column Dialog(). 

 

I would probably used a non-modal New Window() as a control panel instead for this task.

Below is an attempt to simplify your script, still using Column Dialog. I use Eval List() to execute the some of the assignement expressions of the output of Column Dialog, which eliminates the need for extra variables. 

Names Default To Here(1);
dt = Current Data Table();

cd = Column Dialog(
    src=ColList("SOURCES", Min Col(1)),
    trg = ColList("TARGETS", Min Col(1)),
    Line Up(2,
        Text Box("Prefix"), pfx = EditText("P_"),
        Text Box("Suffix"), sfx = EditText("_S")
    )
);
Eval List(cd[[1 2 4 6]]); //Execute relevant assignments within list cd
Show(src, trg, pfx, sfx); // Just to confirm (can be deleted)

n = N Items(src);
m = N Items(trg);

For(i = 1, i <= Min(n, m), i++,
    trg[i] << Set Name(pfx || (src[i] << get name) || sfx)
);
Thierry_S

Contributor

Joined:

Apr 19, 2018

Re: JSL script (rename columns) feedback: it works but I'm not sure why!

Hi MS,
Thank you for your feedback, it is very much appreciated
Best,
TS
Thierry R. Sornasse