<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can you construct this without writing expression as a string? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369603#M61925</link>
    <description>&lt;P&gt;It is also fine to insert--in line--expressions resulting from substitutions, character conversions, etc. As ever, this is a balancing act between ease of interpretation/maintenance and conciseness. In the example below I've done this to illustrate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expression handling is not the easiest thing to learn (or teach). It is quite powerful though, and as you mention, allows you to keep the color-coded text that makes maintenance easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Open("$Sample_data/probe.jmp");

colList = {R_FUSE_16X0_5, VDP_PEMIT, "30P1_4X4_VBE"n, RM_RPB_100X7, "30N4_LE8_2RX1C_BVCBS"n}; //assume we've built this, somehow

gbExpr = Expr(
	gb = Graph Builder(
		Size( 838, 391 ),
		_VAR_EXP_,						// placeholder for Variables ( ) code.
		Elements( _LINE_EXP_ ),			// placeholder for Line ( ) code.
		Local Data Filter( Add Filter( columns( :DELL_RPPBR ), Where( :DELL_RPPBR &amp;gt;= -1 &amp;amp; :DELL_RPPBR &amp;lt;= 0.483837991952896 ) ) )
	)
);

varExpr = Expr( Variables( X( :DELL_RPPBR ) ) );  	//Loop will insert into the last (default) position

lineExpr = Expr( Line( X, Legend( 1 ) ) );			//Loop will insert into the i+1th position

For( i = 1, i &amp;lt;= N Items( colList ), i++,			//note we're inserting the result of a substitute ( ) in each case
	Insert Into( varExpr, Substitute( Expr( Y( Column( _COL_ ), Position( 1 ) ) ), Expr( _COL_ ), Char( colList[i] ) ) );
	Insert Into( lineExpr, Substitute( Expr( Y( _i_ ) ), Expr( _i_ ), i ), i + 1 );
);

Substitute Into( gbExpr, Expr( _VAR_EXP_ ), Name Expr( varExpr ), Expr( _LINE_EXP_ ), Name Expr( lineExpr ) );

gbExpr; //evaluate the (now completely built) expression to show graph
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Mar 2021 13:08:54 GMT</pubDate>
    <dc:creator>brady_brady</dc:creator>
    <dc:date>2021-03-19T13:08:54Z</dc:date>
    <item>
      <title>Can you construct this without writing expression as a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369323#M61907</link>
      <description>&lt;P&gt;I dislike constructing jsl expressions as strings, it makes them hard to troubleshoot and checking for syntax errors is a multistep process. This example solution for &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/19167"&gt;@A_Zaid&lt;/a&gt;'s &lt;LI-MESSAGE title="Plotting conditionally" uid="367827" url="https://community.jmp.com/t5/Discussions/Plotting-conditionally/m-p/367827#U367827" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;post has me struggling though.&amp;nbsp; Is it possible to construct this graph builder function&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt; writing the string and parsing it as text? I'm stuck when trying to construct the 'expression' of Y arguments which is an unknown number of arguments and can't be parsed on its own.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe there an equivalent to &lt;A href="https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/do.call" target="_self"&gt;do.call&lt;/A&gt;, invoke, or &lt;A href="https://rlang.r-lib.org/reference/exec.html" target="_self"&gt;exec&lt;/A&gt; operators in R, or the &lt;A href="https://stackoverflow.com/questions/2322355/proper-name-for-python-operator" target="_self"&gt;splat&lt;/A&gt; operator in Python that I haven't found yet?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = Open("$Sample_data/probe.jmp");

//Variables to hold the dynamic parts of the graph builder expresssion
Expr1 = "";
Expr2 = "";

// Pick columns to include
cols = ( dt &amp;lt;&amp;lt; get column names() )[random shuffle(8::397)[1::5]];

//Populate expressions
for(c=1, c&amp;lt;= n items(cols), c++,
	Expr1 = Expr1 || "Y( Column( \!"" || cols[c] || "\!" ), Position(1) ),";
	Expr2 = Expr2 || "Y( " || char( c ) || " ),";
);

Eval( Parse( substitute(
	//the graph builder script as a string with 'dummy variables' where the
	//expressions created earlier will go
	"gb = Graph Builder(
		Size( 838, 391 ),
		Variables(
			X( :DELL_RPPBR ),
			Expr1_
		),
		Elements( Line( X, Expr2_ Legend( 10 ) ) ),
		Local Data Filter(
			Add Filter(
				columns( :DELL_RPPBR ),
				Where( :DELL_RPPBR &amp;gt;= -1 &amp;amp; :DELL_RPPBR &amp;lt;= 0.483837991952896 )
			)
		)
	)",
	//replace the 'dummy variables'
	"Expr1_",
	Expr1,
	"Expr2_",
	Expr2
) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:08:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369323#M61907</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2023-06-09T22:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369357#M61909</link>
      <description>&lt;P&gt;Eval(Parse()) has saved me on too many occasions. I do not know any other method for your example script.&amp;nbsp; Maybe another community member has a solution&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 02:22:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369357#M61909</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-19T02:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369448#M61914</link>
      <description>&lt;P&gt;I usually just fall back to using Eval(Parse()) because it feels way easier. Found this&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/Use-variable-list-of-columns-as-Y-Axis-in-Graph-Builder/m-p/230473/highlight/true#M45707" target="_blank" rel="noopener"&gt;Re: Use variable list of columns as Y Axis in Graph Builder&lt;/A&gt;&amp;nbsp;where&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5358"&gt;@Mark_Bailey&lt;/a&gt;&amp;nbsp;gives solution to something similar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my attempt with this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$Sample_data/probe.jmp");

cols = (dt &amp;lt;&amp;lt; get column names())[Random Shuffle(8 :: 397)[1 :: 5]];

var expr = Expr(
	Variables(X(:DELL_RPPBR))
);

var line = Expr(Line(X));

For(c = 1, c &amp;lt;= N Items(cols), c++,
	y expr = Expr(Y(Position(1)));
	Insert Into(y expr, cols[c], 1);
	Insert Into(var expr, Name Expr(y expr));
	
	yline expr = Parse("Y("||char(c)||")");
	Insert Into(var line, Name Expr(yline expr));

);

yline expr = Expr(Legend(10));
Insert Into(var line, Name Expr(yline expr));

Eval(
	Substitute(
			Expr(
				gb = dt &amp;lt;&amp;lt; Graph Builder(
					Size(838, 391),
					Show Control Panel(0),
					vvv,
					Elements(yyy),
					Local Data Filter(Conditional, Add Filter(columns(:DELL_RPPBR), 
						Where(:DELL_RPPBR &amp;gt;= -1 &amp;amp; :DELL_RPPBR &amp;lt;= 0.483837991952896)))
				)
			),
		Expr(vvv), Name Expr(var expr),
		Expr(yyy), Name Expr(var line)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought that this wouldn't help at all with debugging but it does because you can just run the Substitute() part of graph builder generation to see what it tries to do (and you also get JSL syntax highlighting).&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 06:11:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369448#M61914</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-03-19T06:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression as a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369603#M61925</link>
      <description>&lt;P&gt;It is also fine to insert--in line--expressions resulting from substitutions, character conversions, etc. As ever, this is a balancing act between ease of interpretation/maintenance and conciseness. In the example below I've done this to illustrate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expression handling is not the easiest thing to learn (or teach). It is quite powerful though, and as you mention, allows you to keep the color-coded text that makes maintenance easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Open("$Sample_data/probe.jmp");

colList = {R_FUSE_16X0_5, VDP_PEMIT, "30P1_4X4_VBE"n, RM_RPB_100X7, "30N4_LE8_2RX1C_BVCBS"n}; //assume we've built this, somehow

gbExpr = Expr(
	gb = Graph Builder(
		Size( 838, 391 ),
		_VAR_EXP_,						// placeholder for Variables ( ) code.
		Elements( _LINE_EXP_ ),			// placeholder for Line ( ) code.
		Local Data Filter( Add Filter( columns( :DELL_RPPBR ), Where( :DELL_RPPBR &amp;gt;= -1 &amp;amp; :DELL_RPPBR &amp;lt;= 0.483837991952896 ) ) )
	)
);

varExpr = Expr( Variables( X( :DELL_RPPBR ) ) );  	//Loop will insert into the last (default) position

lineExpr = Expr( Line( X, Legend( 1 ) ) );			//Loop will insert into the i+1th position

For( i = 1, i &amp;lt;= N Items( colList ), i++,			//note we're inserting the result of a substitute ( ) in each case
	Insert Into( varExpr, Substitute( Expr( Y( Column( _COL_ ), Position( 1 ) ) ), Expr( _COL_ ), Char( colList[i] ) ) );
	Insert Into( lineExpr, Substitute( Expr( Y( _i_ ) ), Expr( _i_ ), i ), i + 1 );
);

Substitute Into( gbExpr, Expr( _VAR_EXP_ ), Name Expr( varExpr ), Expr( _LINE_EXP_ ), Name Expr( lineExpr ) );

gbExpr; //evaluate the (now completely built) expression to show graph
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Mar 2021 13:08:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369603#M61925</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-03-19T13:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression as a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369608#M61927</link>
      <description>&lt;P&gt;I got this far but I can't work on it any more today. There is an error in the expression using the Name() directive. There is a way around it but I do not have time now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Open( "$Sample_data/probe.jmp" );

//Variables to hold the dynamic parts of the graph builder expresssion
response expr = Expr(
	Variables( X( :DELL_RPPBR ) )
);

line expr = Expr(
	Line( X, Legend( 10 ) )
);

// Pick columns to include
col = (dt &amp;lt;&amp;lt; Get Column Names)[Random Shuffle( 10 :: 397 )[1 :: 5]];

//Populate expressions
For( c = 1, c &amp;lt;= N Items( col ), c++,
	Insert Into( response expr, Substitute( Expr( Y( Name( ccc ), Position( 1 ) ) ), Expr( ccc ), Char( col[c], 1 ) ) );
	Insert Into( line expr, Substitute( Expr( Y( ccc ) ), Expr( ccc ), c ), c+1 );
);

Eval(
	Substitute( 
		Expr(
			gb = dt &amp;lt;&amp;lt; Graph Builder(
				Size( 838, 391 ),
				Variables(
					vvv
				),
				Elements( Line( X, lll, Legend( 10 ) ) ),
				Local Data Filter(
					Add Filter(
						Columns( :DELL_RPPBR ),
						Where( -1 &amp;lt; :DELL_RPPBR &amp;lt;= 0.483837991952896 )
					)
				)
			)
		),
		Expr( vvv ), Name Expr( response expr ),
		Expr( lll ), Name Expr( line expr )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Mar 2021 13:40:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369608#M61927</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-03-19T13:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369629#M61929</link>
      <description>&lt;P&gt;Aah ha, using Insert Into() to build a function expression instead of a list is a great solution.&amp;nbsp; I will give this a try this evening, I see the light, thanks all!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 13:47:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369629#M61929</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-03-19T13:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression as a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369935#M61966</link>
      <description>&lt;P&gt;The&lt;EM&gt; insert into&lt;/EM&gt; approach looks really good; I'm going to remember that. I'd been using a { list of expressions } and replacing the {} with the new head, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$Sample_data/probe.jmp" );
// Pick columns to include
cols = (dt &amp;lt;&amp;lt; get column names())[Random Shuffle( 8 :: 397 )[1 :: 5]];

//Variables to hold the dynamic parts of the graph builder expresssion
List1 = {};
List2 = {};

//Populate expressions
For( c = 1, c &amp;lt;= N Items( cols ), c++,
	List1[c] = Eval Expr( Y( Expr( cols[c] ), Position( 1 ) ) );
	List2[c] = Eval Expr( Y( Expr( c ) ) );
);
// list1: {Y( Name( "M1-TRENCH_ISO_IL" ), Position( 1 ) ), Y(...
// list2: {Y( 1 ), Y( 2 ), Y( 3 ), Y( 4 ), Y( 5 )}
Insert Into( List1, Expr( X( :DELL_RPPBR ) ), 1 ); // front of list1
Insert Into( List2, Expr( X ), 1 ); // front of list2
Insert Into( List2, Expr( Legend( 10 ) ) ); // back of list2

// swap the {} for variables() and line()
variablesExpr = Substitute( List1, Expr( {} ), Expr( variables() ) );
lineExpr = Substitute( List2, Expr( {} ), Expr( Line() ) );

exprGB = Expr(
	//the graph builder script as a string with 'dummy variables' where the
	//expressions created earlier will go
	(Graph Builder(
		Size( 838, 391 ),
		Variables_,
		Elements( Line_ ),
		Local Data Filter( Add Filter( columns( :DELL_RPPBR ), Where( :DELL_RPPBR &amp;gt;= -1 &amp;amp; :DELL_RPPBR &amp;lt;= 0.483837991952896 ) ) )
	))
);

Substitute Into( exprGB, Expr( Variables_ ), Name Expr( variablesExpr ), Expr( Line_ ), Name Expr( lineExpr ) );

Show( Name Expr( exprGB ) );

Eval( exprGB );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;edit...&lt;/P&gt;&lt;P&gt;And InsertInto and RemoveFrom both work with positions in an expression. Cool, I really need to remember that!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 01:41:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/369935#M61966</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-03-20T01:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can you construct this without writing expression as a string?</title>
      <link>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/549606#M76604</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;I only now realized the power of what you suggested here, I didn't know you can use substitute to modify non-continuous parts of an expression. This method essentially&amp;nbsp;&lt;EM&gt;is &lt;/EM&gt;what the R function &lt;A href="https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/do.call" target="_self" rel="nofollow noopener noreferrer"&gt;do.call&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;does (recreated below), and is similar to&amp;nbsp;&lt;SPAN&gt;invoke or&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://rlang.r-lib.org/reference/exec.html" target="_self" rel="nofollow noopener noreferrer"&gt;exec&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;operators in R, or the&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://stackoverflow.com/questions/2322355/proper-name-for-python-operator" target="_self" rel="nofollow noopener noreferrer"&gt;splat&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;operator in python&lt;/SPAN&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//call another function (f) with the arguments provided in a list (l)
do.call = function({l,f}, 
	Eval(Substitute(
		Name Expr(l),
		Expr({}),
		Name Expr(f)
	) );
);

//as an example, this calls concat("a", "b", "c")
do.call({"a","b","c"}, Expr(concat()))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Nice!!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 21:43:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Can-you-construct-this-without-writing-expression-as-a-string/m-p/549606#M76604</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2022-09-26T21:43:06Z</dc:date>
    </item>
  </channel>
</rss>

