你能在不將表達式寫成字符串的情況下構造這個嗎?我不喜歡將 jsl 表達式構建為字符串,這使得它們難以排除故障,並且檢查語法錯誤是一個多步驟的過程。 此示例解決方案適用於@A_Zaid的有條件地繪圖不過,帖子讓我很掙扎。是否可以構造這個圖形生成器函數沒有編寫字符串並將其解析為文本? 當我嘗試構造 Y 參數的“表達式”時,我陷入了困境,該參數的參數數量未知,並且無法自行解析。
也許有一個相當於打電話、調用或執行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
) ) );
自動化和腳本編寫回复:您可以在不將表達式寫為字符串的情況下構造這個嗎?@Craige_Hales我現在才意識到你在這裡建議的力量,我不知道你可以使用替代來修改表達式的非連續部分。 這個方法本質上是是R 函數是什麼打電話確實(下面重新創建),並且類似於調用或執行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()))
好的!!
回复:您可以在不將表達式寫為字符串的情況下構造這個嗎?這插入方法看起來確實不錯;我會記住這一點。 我一直在使用 { 表達式列表 } 並將 {} 替換為新的頭,如下所示:
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 都可以處理表達式中的位置。 酷,我真的需要記住這一點!
回复:您可以在不將表達式寫成字符串的情況下構造這個嗎?啊哈,使用 Insert Into() 構建函數表達式而不是列表是一個很好的解決方案。今晚我會嘗試一下,我看到了曙光,謝謝大家!
回复:您可以在不將表達式寫為字符串的情況下構造這個嗎?我已經做到了這一點,但今天我無法再繼續下去了。 使用 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 )
)
);回复:您可以在不將表達式寫為字符串的情況下構造這個嗎?也可以在行中插入由替換、字符轉換等產生的表達式。一如既往,這是易於解釋/維護和簡潔性之間的平衡行為。 在下面的示例中,我這樣做是為了說明。
表達式處理並不是最容易學習(或教授)的事情。 它非常強大,正如您所提到的,它允許您保留顏色編碼的文本,從而使維護更容易。
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
回复:您可以在不將表達式寫入字符串的情況下構造這個嗎?我通常會轉而使用 Eval(Parse()) 因為它感覺更容易。 找到了這個回复:在圖形生成器中使用變量列列表作為 Y 軸在哪裡@馬克貝利給出類似問題的解決方案。
這是我的嘗試:
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 語法突出顯示)。
回复:您可以在不將表達式寫入字符串的情況下構造這個嗎?Eval(Parse()) 在很多場合拯救了我。 我不知道您的示例腳本有任何其他方法。也許另一個社區成員有解決方案