I started with @julian 's idea to use the table script and added some functions to
- search for columns in the formulas and
- to display the search results:
//Open( "$SAMPLE_DATA/Ship Damage.jmp" );
// get all column formulas via the table script
dt = Current Data Table();
dt << copy table script( "No Data" );
script = Parse( Get Clipboard() );
//convert to List for easier indexing
Substitute Into( script, Expr( New Table() ), Expr( {} ) );
// just keep the columns
allCols = Filter Each( {col}, script, Head( col ) == Expr( New Column() ) );
// convert column info into lists
ColList = Transform Each( {col}, allCols, Substitute( Name Expr( col ), Expr( New Column() ), Expr( {} ) ) );
allColNames = Transform Each( {col}, ColList, tmp = Arg( col, 1 ); If (is string(tmp), tmp, tmp["en"]) );
// keep columns with formulas
ColsWithFormulas = Filter Each( {col}, ColList,Try(col["Formula"]; 1 , 0 ));
ColNames = Transform Each( {col}, ColsWithFormulas, tmp = Arg( col, 1 ); If (is string(tmp), tmp, tmp["en"]) );
ColFormulas = Transform Each( {col}, ColsWithFormulas, col["Formula"] );
// helper function to search for column names in formulas
ContainsExpr = Function( {expression, pattern},
tmp = Substitute( Name Expr( expression ), Name Expr( pattern ), Expr( . ) );
Not( Name Expr( tmp ) == Name Expr( expression ) );
);
summary = New Table("Formuala Overview",
New Column( "column Formula", Character ),
New Column( "used cols", Character ),
);
wait(0);
// fill the summary tale with all combinations of formulas and the used columns
Current Data Table( dt ); // make dt the current data table, otherwise <As column> won't work !
For Each( {myFormula, idx1}, ColFormulas,
For Each( {col}, allColNames,
formulaCol = ColNames[idx1];
dt:formulaCol << Set Header Text Color( "Red" );
If( ContainsExpr( Name Expr( myFormula ), Name Expr( As Column( col ) ) ),
Eval( Eval Expr( summary << add row( {"column Formula"n =Expr(formulaCol ), "used cols"n = Expr( col )} ) ) );
Column(col) << Set Header Background Color( {102, 255, 140} );
)
)
);
// show a tabulate for easy look up
summary << Tabulate(
Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( :column Formula, :used cols ) ) ),
Local Data Filter( Mode( Show( 0 ) ), Add Filter( columns( :column Formula, :used cols ) ) )
);