Hello,
I'm learning to work with expression manipulations and I'm having a difficult time wrapping my head around it.
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.
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. This section doesn't work.
Does anyone have any helpful tips or see something that I'm misunderstanding about how expression manipulations work? Thank you in advanced!
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 <= 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 <-- 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 <= 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") };
Learning every day!