式を文字列として書かずにこれを構築できますか?私は jsl 式を文字列として構築するのが好きではありません。トラブルシューティングが難しくなり、構文エラーのチェックは複数のステップからなるプロセスになります。 このソリューション例は、 @A_Zaidさんの条件付きでプロットする投稿には苦労していますが。このグラフビルダー関数を構築することは可能ですかそれなし文字列を書き込んでテキストとして解析しますか? Y 引数の「式」を構築しようとすると、引数の数が不明であり、単独で解析できない場合に行き詰まってしまいます。
おそらく同等のものがあるでしょうdo.call 、呼び出す、または実行するR の演算子、またはスプラットまだ見つけていない Python の演算子はありますか?
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
) ) );
自動化とスクリプト作成Re:式を文字列として書かずにこれを構築できますか?@Craige_Hales私は今ここであなたが提案したものの威力に気づきました。式の非連続部分を変更するために replace を使用できるとは知りませんでした。 この方法は基本的にはR関数とは何ですかdo.call (以下に再作成) を実行し、次のようになります。呼び出すか、実行するR の演算子、またはスプラット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()))
良い!!
Re:式を文字列として書かずにこれを構築できますか?のに挿入するアプローチはとても良さそうです。それを覚えていきます。 次のように、{ 式のリスト } を使用し、{} を新しいヘッドに置き換えていました。
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 );編集...
また、InsertInto と RemoveFrom はどちらも式内の位置を操作します。 いいですね、それはぜひ覚えておきたいですね!
Re: 文字列式を書かずにこれを構築できますか?ああ、Insert Into() を使用してリストの代わりに関数式を構築するのは素晴らしい解決策です。今晩これを試してみます、光が見えました、皆さんありがとう!
Re:式を文字列として書かずにこれを構築できますか?ここまではできましたが、今日はこれ以上作業できません。 Name() ディレクティブを使用した式にエラーがあります。 回避する方法はありますが、今は時間がありません。
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 )
)
);Re:式を文字列として書かずにこれを構築できますか?置換や文字変換などの結果として得られる式を行内に挿入することもできます。これまでと同様に、これは解釈/保守の容易さと簡潔さの間のバランスを取る必要があります。 以下の例では、説明するためにこれを行っています。
式の処理は、学ぶ (または教える) のが最も簡単なものではありません。 ただし、これは非常に強力であり、あなたが言及したように、色分けされたテキストを保持できるため、メンテナンスが容易になります。
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: 文字列式を書かずにこれを構築できますか?私は通常、Eval(Parse()) を使用することに戻ってしまいます。そのほうが簡単だと思うからです。 これを見つけましたRe: グラフ ビルダーで列の変数リストを Y 軸として使用するどこ@Mark_Bailey同様のものに対する解決策を示します。
これを使った私の試みは次のとおりです。
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)
)
);これはデバッグにはまったく役に立たないと思いましたが、グラフビルダー生成の Substitute() 部分を実行するだけで、それが何をしようとしているのかを確認できるため、役に立ちます (JSL 構文の強調表示も表示されます)。
Re: 文字列式を書かずにこれを構築できますか?Eval(Parse()) は私を何度も救ってくれました。 あなたのサンプルスクリプトの他の方法はわかりません。コミュニティの他のメンバーが解決策を持っているかもしれません