<?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 Inserting expression into list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608588#M81002</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm learning to work with expression manipulations and I'm having a difficult time wrapping my head around it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the first section of the code below, I can successfully insert the string column name into the column() expression, but I cannot insert the generated expressions into a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second section breaks apart interaction terms (this is an effect list from SLS), inserts them into their own column() expression, pieces them back together as an interaction term, and then inserts that into a list.&amp;nbsp; This section doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any helpful tips or see something that I'm misunderstanding about how expression manipulations work?&amp;nbsp; Thank you in advanced!&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);

// Basic need below - but only works for single column names
collist = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5" };

newlist = {};

for( i = 1, i &amp;lt;= N items(collist), i++,

	// Empty arg to identify cols by names
	name_arg = Expr( column() );

	insert into( name_arg, eval insert( collist[i] ) ); // result: column("Col 1"), or other cols inserted &amp;lt;-- Working as intended
	
	show( name_arg );  // Shows successful insert into's
	
	insert into( newlist, insert into( name_arg, eval insert( collist[i] ) ) );
	// Nested insert into doesn't work
	// Need to insert the result of the first insert into, into newlist

);

show( newlist ); // Currently shows empty list

/////////////////////////////////////////  DOES NOT WORK, BELOW

// Advanced flow - interaction detection 
collist2 = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5", "Col 1*Col 2", "Col 2*Col 4", "Col 5*Col 5" };

newlist2 = {};

for( a = 1, a &amp;lt;= N items( collist2 ), a++,

	// Empty arg to identify cols by names
	name_arg = Expr( column() );
	
	// For whatever the match below, the result must be added to newlist2
	// Regex works, as per regex101.com
	if( !contains( collist2[a], "*" ), insert into( name_arg2, eval insert( collist2[a] ) ), // single term insert, refer to basic needs flow above
		insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\1" ) ) ); // Breaks apart 1st group to insert into column()
		insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\2" ) ) ); // Breaks apart 2nd group to insert into column()
		
		// The line below is a mockup of joining back together the first and second group together as interaction terms - doesn't work
		//eval expr( expr( insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\1" ) ) )*insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\2" ) ) );
	)
	
);

Desired_output = { column("Col 1"), column("Col 2"), column("Col 3"), column("Col 4"), column("Col 5"), column("Col 1")*column("Col 2"),
	column("Col 2")*column("Col 4"), column("Col 5")*column("Col 5") };&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Jun 2023 16:31:09 GMT</pubDate>
    <dc:creator>StarfruitBob</dc:creator>
    <dc:date>2023-06-08T16:31:09Z</dc:date>
    <item>
      <title>Inserting expression into list</title>
      <link>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608588#M81002</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm learning to work with expression manipulations and I'm having a difficult time wrapping my head around it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the first section of the code below, I can successfully insert the string column name into the column() expression, but I cannot insert the generated expressions into a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second section breaks apart interaction terms (this is an effect list from SLS), inserts them into their own column() expression, pieces them back together as an interaction term, and then inserts that into a list.&amp;nbsp; This section doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any helpful tips or see something that I'm misunderstanding about how expression manipulations work?&amp;nbsp; Thank you in advanced!&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);

// Basic need below - but only works for single column names
collist = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5" };

newlist = {};

for( i = 1, i &amp;lt;= N items(collist), i++,

	// Empty arg to identify cols by names
	name_arg = Expr( column() );

	insert into( name_arg, eval insert( collist[i] ) ); // result: column("Col 1"), or other cols inserted &amp;lt;-- Working as intended
	
	show( name_arg );  // Shows successful insert into's
	
	insert into( newlist, insert into( name_arg, eval insert( collist[i] ) ) );
	// Nested insert into doesn't work
	// Need to insert the result of the first insert into, into newlist

);

show( newlist ); // Currently shows empty list

/////////////////////////////////////////  DOES NOT WORK, BELOW

// Advanced flow - interaction detection 
collist2 = { "Col 1", "Col 2", "Col 3", "Col 4", "Col 5", "Col 1*Col 2", "Col 2*Col 4", "Col 5*Col 5" };

newlist2 = {};

for( a = 1, a &amp;lt;= N items( collist2 ), a++,

	// Empty arg to identify cols by names
	name_arg = Expr( column() );
	
	// For whatever the match below, the result must be added to newlist2
	// Regex works, as per regex101.com
	if( !contains( collist2[a], "*" ), insert into( name_arg2, eval insert( collist2[a] ) ), // single term insert, refer to basic needs flow above
		insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\1" ) ) ); // Breaks apart 1st group to insert into column()
		insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\2" ) ) ); // Breaks apart 2nd group to insert into column()
		
		// The line below is a mockup of joining back together the first and second group together as interaction terms - doesn't work
		//eval expr( expr( insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\1" ) ) )*insert into( name_arg2, eval insert( regex( mylist2[a], "^(.*)\*(.*)$", "\2" ) ) );
	)
	
);

Desired_output = { column("Col 1"), column("Col 2"), column("Col 3"), column("Col 4"), column("Col 5"), column("Col 1")*column("Col 2"),
	column("Col 2")*column("Col 4"), column("Col 5")*column("Col 5") };&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:31:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608588#M81002</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-06-08T16:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting expression into list</title>
      <link>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608601#M81004</link>
      <description>&lt;P&gt;The first section, where I'm wanting to insert expressions into a list, can easily be solved by the line of code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;insert into( newlist, name expr( name_arg ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Onto solving the next section!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 17:28:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608601#M81004</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-06T17:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting expression into list</title>
      <link>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608643#M81010</link>
      <description>&lt;P&gt;Got the second part of the script to work, the one with interaction terms!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for( a = 1, a &amp;lt;= N items( collist2 ), a++,

	// Empty arg to identify cols by names
	name_arg = Expr( column() );
	name_arg2 = Expr( column() );
	
	// For whatever the match below, the result must be added to newlist2
	// Regex works, as per regex101.com
	if( !contains( collist2[a], "*" ), insert into( name_arg, eval insert( collist2[a] ) );
			insert into( newlist2, name expr( name_arg ) ), // single term insert, refer to basic needs flow above
		insert into( name_arg, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\1" ) ) ); // Breaks apart 1st group to insert into column()
		insert into( name_arg2, eval insert( regex( collist2[a], "^(.*)\*(.*)$", "\2" ) ) ); // Breaks apart 2nd group to insert into column()
		insert into( newlist2, Eval Expr( expr( name_arg )*expr( name_arg2 ) ) );

	);
	
);

show( newlist2 );

Output:
newlist2 = {Column("Col 1"), Column("Col 2"), Column("Col 3"), Column("Col 4"), Column("Col 5"), Column("Col 1") * Column("Col 2"), Column("Col 2") * Column("Col 4"), Column("Col 5") * Column("Col 5")};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hopefully this helps guide others learning expression manipulations. It's a long journey - but it's powerful and worth it! :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 18:27:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Inserting-expression-into-list/m-p/608643#M81010</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-06T18:27:56Z</dc:date>
    </item>
  </channel>
</rss>

