Puoi costruirlo senza scrivere espressione come una stringa?Non mi piace costruire espressioni jsl come stringhe, le rende difficili da risolvere e il controllo degli errori di sintassi è un processo in più passaggi. Questa soluzione di esempio per @A_Zaid 'S Tracciare in modo condizionale il post mi fa faticare però.È possibile costruire questa funzione di generatore di grafici senza scrivere la stringa e analizzarla come testo? Sono bloccato quando provo a costruire l '"espressione" degli argomenti Y che è un numero sconosciuto di argomenti e non può essere analizzato da solo.
Forse c'è un equivalente a fare.chiamare , invocare, o esec operatori in R, o il schizzare operatore in Python che non ho ancora trovato?
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 << get column names() )[random shuffle(8::397)[1::5]];
//Populate expressions
for(c=1, c<= 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 >= -1 & :DELL_RPPBR <= 0.483837991952896 )
)
)
)",
//replace the 'dummy variables'
"Expr1_",
Expr1,
"Expr2_",
Expr2
) ) );
Automazione e scriptingRi: Puoi costruirlo senza scrivere espressione come una stringa?@Craige_Hales Solo ora ho realizzato il potere di ciò che hai suggerito qui, non sapevo che puoi usare sostituto per modificare parti non continue di un'espressione. Questo metodo essenzialmente È qual è la funzione R fare.chiamare fa (ricreato sotto), ed è simile a invocare o esec operatori in R, o il schizzare operatore in python :
//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()))
Carino!!
Ri: Puoi costruirlo senza scrivere espressione come una stringa?IL inserire l'approccio sembra davvero buono; Me lo ricorderò. Stavo usando un { elenco di espressioni } e sostituendo {} con la nuova testa, in questo modo:
dt = Open( "$Sample_data/probe.jmp" );
// Pick columns to include
cols = (dt << 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 <= 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 >= -1 & :DELL_RPPBR <= 0.483837991952896 ) ) )
))
);
Substitute Into( exprGB, Expr( Variables_ ), Name Expr( variablesExpr ), Expr( Line_ ), Name Expr( lineExpr ) );
Show( Name Expr( exprGB ) );
Eval( exprGB );modificare...
E InsertInto e RemoveFrom funzionano entrambi con le posizioni in un'espressione. Fantastico, devo proprio ricordarmelo!
Re: Puoi costruirlo senza scrivere espressione una stringa?Aah ah, usare Insert Into() per creare un'espressione di funzione invece di un elenco è un'ottima soluzione.Proverò questa sera, vedo la luce, grazie a tutti!
Ri: Puoi costruirlo senza scrivere espressione come una stringa?Sono arrivato fin qui ma non posso più lavorarci oggi. C'è un errore nell'espressione che utilizza la direttiva Name(). C'è un modo per aggirarlo, ma non ho tempo adesso.
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 << Get Column Names)[Random Shuffle( 10 :: 397 )[1 :: 5]];
//Populate expressions
For( c = 1, c <= 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 << Graph Builder(
Size( 838, 391 ),
Variables(
vvv
),
Elements( Line( X, lll, Legend( 10 ) ) ),
Local Data Filter(
Add Filter(
Columns( :DELL_RPPBR ),
Where( -1 < :DELL_RPPBR <= 0.483837991952896 )
)
)
)
),
Expr( vvv ), Name Expr( response expr ),
Expr( lll ), Name Expr( line expr )
)
);Ri: Puoi costruirlo senza scrivere espressione come una stringa?Va bene anche inserire - in riga - espressioni risultanti da sostituzioni, conversioni di caratteri, ecc. Come sempre, questo è un atto di equilibrio tra facilità di interpretazione/manutenzione e concisione. Nell'esempio qui sotto ho fatto questo per illustrare.
La gestione delle espressioni non è la cosa più facile da imparare (o insegnare). Tuttavia è abbastanza potente e, come dici tu, ti consente di mantenere il testo con codice colore che semplifica la manutenzione.
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 >= -1 & :DELL_RPPBR <= 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 <= 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
Re: Puoi costruirlo senza scrivere espressione una stringa?Di solito ripiego sull'uso di Eval(Parse()) perché sembra molto più semplice. Trovato questo Oggetto: Usa l'elenco variabile di colonne come asse Y nel Costruttore di grafici Dove @Mark_Bailey dà soluzione a qualcosa di simile.
Ecco il mio tentativo con questo:
Names Default To Here(1);
dt = Open("$Sample_data/probe.jmp");
cols = (dt << 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 <= 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 << Graph Builder(
Size(838, 391),
Show Control Panel(0),
vvv,
Elements(yyy),
Local Data Filter(Conditional, Add Filter(columns(:DELL_RPPBR),
Where(:DELL_RPPBR >= -1 & :DELL_RPPBR <= 0.483837991952896)))
)
),
Expr(vvv), Name Expr(var expr),
Expr(yyy), Name Expr(var line)
)
);Ho pensato che questo non avrebbe aiutato affatto con il debug, ma lo fa perché puoi semplicemente eseguire la parte Substitute() della generazione del generatore di grafici per vedere cosa cerca di fare (e ottieni anche l'evidenziazione della sintassi JSL).
Re: Puoi costruirlo senza scrivere espressione una stringa?Eval(Parse()) mi ha salvato in troppe occasioni. Non conosco nessun altro metodo per il tuo script di esempio.Forse un altro membro della comunità ha una soluzione