Passing column name as argument to a function - is concatenating with : needed?Below is a function where I am trying to pass a column name for plotting a distribution, but it is not working. I am wondering what is the correct syntax?
Names Default To Here (1);
getDistChart = Function({ColName}, {dC},
dC = Distribution( Continuous Distribution( Column( :ColName) ) );
return(dC);
);
//gt = getDistChart ("MyCol"); to test the function
I have already got the data table with MyCol as a column name open. I am wondering if I need to concatenate
:
with the column name
ColName
If so how (as normal concatenation with || || does not seem to be working)?
Data TableScriptingRe: Passing column name as argument to a function - is concatenating with : needed?Thanks @Mark_Bailey This works.
Re: Passing column name as argument to a function - is concatenating with : needed?Yes, it works perfectly for me with JMP Pro 16.1.0. I do not have any earlier versions of JMP installed to test. Your version is about 5 years old. JSL is constantly evolving, so it is possible that my syntax does not work for an earlier version.
You might contact JMP Technical Support (support@jmp.com) for help.
You might also try using expressions to accomplish what you want. They work for any version of JMP, since version 4. See if this version works:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName, _LSL, _USL}, {distChart},
Eval(
Substitute(
Expr(
distChart = New Window( "" || ColName || " distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column( As Column( ColName ) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL( _LSL ), USL( _USL ) )
),
SendToReport(
Dispatch(
{ ccc },
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
)
);
),
Expr( ccc ), colName
)
);
Return( distChart );
);
getDistChart( "weight", 55, 185 );Re: Passing column name as argument to a function - is concatenating with : needed?@Mark_Bailey Thanks. Running your script gives me the following in the log
Cannot find item "ColName" in outline context {ColName}
Does it work for you?
(I am on JMP 13)
Re: Passing column name as argument to a function - is concatenating with : needed?Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName, _LSL, _USL},
{distChart},
New Window( "" || ColName || " distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column( As Column( ColName ) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL( _LSL ), USL( _USL ) )
),
SendToReport(
Dispatch(
{colName},
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
)
);
Return( distChart );
);
getDistChart( "weight", 55, 185 );Re: Passing column name as argument to a function - is concatenating with : needed?@Mark_Bailey Thanks it works. However, I am getting stuck advancing to the next step. I would like to pass the column name to several places in my script. Using Big Class as an example below. I am able to pass the ColName to New Window but not to Dispatch
Names Default To Here (1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function({ColName, _LSL, _USL}, {distChart},
New Window(""||ColName||" distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column(As Column (ColName) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL(_LSL ), USL(_USL) )
),
SendToReport(
Dispatch(
{"weight"},
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
);
);
return(distChart);
);
getDistChart ("weight", 55, 185);
For example this
Dispatch( {ColName},...
or this from here
Dispatch( {Expr(ColName)},...
does not work. What is the correct syntax to pass a string as argument for Dispatch?
Re: Passing column name as argument to a function - is concatenating with : needed?Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName}, {dC},
dC = Distribution( Continuous Distribution( Column( As Column( colName ) ) ) );
Return( dC );
);
gt = getDistChart ("weight");