I was able to come up with this script. Wasn't sure how to shorten the transform into an "if" statement.
@ian_jmp
NamesDefaultToHere(1);
// Make a table to use
nr = 100; // Number of rows
nc = 10; // Number of columns
dt = AsTable(J(nr, nc, RandomNormal()));
dt << setName("Example Data");
// Make a UI to allow selection of columns from the current data table
dt = CurrentDataTable();
nw = NewWindow("New Column Transforms",
TextBox("Select all transforms to perform", << fontColor("Blue")),
VListBox(
cb=CheckBox({"Plus","Minus","Times","DivideBy"},
Print(
"Selected: " || Concat Items(cb <<GetSelected(), ", ")
)
)
),
TextBox("Select columns:", << fontColor("Blue")),
clb = ColListBox(all, numeric),
LineUpBox(NCol(2),
ButtonBox("OK", OKscript),
ButtonBox("Cancel", nw << closeWindow)
);
);
nw << setWindowSize(500, 900);
// This script runs if the user hits 'OK'
OKScript =
Expr(
nw << closeWindow;
// Get which transforms were selected
tList = cb <<getSelected;
// Get which columns were selected
colList = clb << getSelected;
// Define a formula column for each pairwise difference
for(t=1, t<=NItems(tList), t++,
for(c1=2, c1<=NItems(colList), c1++,
for(c2=1, c2<c1, c2++,
if(tList[t]=="Plus",
addCol = Expr(
dt << NewColumn(colList[c1]||" plus "||colList[c2],
Numeric, Continuous,
Formula(AsColumn(c1TBD) + AsColumn(c2TBD))
)
);
SubstituteInto(addCol, Expr(c1TBD), NameExpr(colList[c1]), Expr(c2TBD), NameExpr(colList[c2]));
addCol;,
tList[t]=="Minus",
addCol = Expr(
dt << NewColumn(colList[c1]||" minus "||colList[c2],
Numeric, Continuous,
Formula(AsColumn(c1TBD) - AsColumn(c2TBD))
)
);
SubstituteInto(addCol, Expr(c1TBD), NameExpr(colList[c1]), Expr(c2TBD), NameExpr(colList[c2]));
addCol;,
tList[t]=="Times",
addCol = Expr(
dt << NewColumn(colList[c1]||" times "||colList[c2],
Numeric, Continuous,
Formula(AsColumn(c1TBD) * AsColumn(c2TBD))
)
);
SubstituteInto(addCol, Expr(c1TBD), NameExpr(colList[c1]), Expr(c2TBD), NameExpr(colList[c2]));
addCol;,
tList[t]=="DivideBy",
addCol = Expr(
dt << NewColumn(colList[c1]||" divideBy "||colList[c2],
Numeric, Continuous,
Formula(AsColumn(c1TBD) / AsColumn(c2TBD))
)
);
SubstituteInto(addCol, Expr(c1TBD), NameExpr(colList[c1]), Expr(c2TBD), NameExpr(colList[c2]));
addCol;
)
)
)
)
);