昨天我發現了以下線程,這讓我調查了 parse()。
https://community.jmp.com/t5/Discussions/evaluating-a-string-using-a-column-formula/mp/38028
思考過程如下:
- 使用 expr() 時,JMP 期望函數作為參數,而不是其他參數。 稍後會詳細介紹。
- 如果參數可以作為字符串保存到變量中,然後放入另一個參數或函數中,這將有助於編寫所需的代碼
這是一個例子。
names default to here(1);
clear log();
clear symbols();
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Solid", "Black", "Tall", 1 )}
)
)
);該腳本打開 Big Class.jmp,然後生成帶有參考線的可視化。 當我想從其他來源提取數據以進行可視化時,我可以將上面的腳本修改為以下內容。
Names default to here(1);
clear log();
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
// Example "other" source
ex = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
dt << Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( ex:Height tag[1], "Solid", "Black", ex:Growth Label[1], 1 )} // 2x references to data table( "Example" ) as "ex"
)
)
);上述腳本的不同之處在於,一些參考線信息現在是從創建的示例表中提取的。如果我想將上面腳本中的可視化添加為數據表腳本怎麼辦?假設我們不想總是引用另一個表的值,我們如何用它們代表的值替換引用?答案是表達式操作,似乎是 parse()。
要閱讀有關表達式操作的更多信息,請閱讀此資源: https://www.jmp.com/support/help/en/17.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#
如果我們要將可視化作為表腳本添加到 Big Class,我們的腳本窗口將包含這樣的代碼。
// Visualization - No references to other data sources
dt << New script( "Vis 1",
Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Solid", "Black", "Tall", 1 )}
)
)
);
);
// Visualization - With references to other data sources
// This will not work, as the data table reference "ex" is undefined
// We could replace ex with data table( "example" ), but that table would need to be open in the background
dt << New script( "Vis 2",
Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( ex:Height tag[1], "Solid", "Black", ex:Growth Label[1], 1 )}
)
)
);
);這是我迄今為止調查和實驗的成果,重點是 parse()。它還沒有起作用,但它是朝著正確方向邁出的一步!
names default to here(1);
clear log();
clear symbols();
// Opening & creating data tables for use
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
ex = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
// Variables
graphing = expr( Graph Builder() );
size = "Size( 517, 447 )";
control_panel = "Show Control Panel( 0 )";
fit = "Fit to Window";
a_lvl = "Set α Level( 0.05 )";
vars = "Variables( X( :weight ), Y( :height ), Color( :sex ) )";
eles = "Elements( Points( X, Y, Legend( 3 ) ) )";
str = "SendToReport()";
disp = parse( "Dispatch()" );
curly = "{}";
label = "ex:Growth label[1]";
label2 = "height";
scle = "ScaleBox";
x_axis = "x()";
test_label = "ex:Height tag[1]";
mylabel = "ex:Growth label[1]";
ref_line = parse( "Add Ref Line()" );
insert into( graphing, parse( size ) );
insert into( graphing, parse( control_panel ) );
insert into( graphing, parse( fit ) );
insert into( graphing, parse( a_lvl ) );
insert into( graphing, parse( vars ) );
insert into( graphing, parse( eles ) );
show( graphing ); // Result:graphing = Graph Builder(Size(517, 447), Show Control Panel(0), Fit to Window, Set α Level(0.05), Variables(X(:weight), Y(:height), Color(:sex)), Elements(Points(X, Y, Legend(3))));
// add ref line
insert into( ref_line, eval( parse( test_label ) ) );
insert into( ref_line, "Solid" );
insert into( ref_line, "Black" );
insert into( ref_line, eval( parse( mylabel ) ) );
show( ref_line ); // Result: ref_line = Add Ref Line(67.5, "Solid", "Black", "Tall");
insert into( disp, parse( curley ) );
insert into( disp, eval( parse( mylabel ) ) );
insert into( disp, char( label2 ) );
insert into( disp, parse( scle ) );
insert into( disp, parse( curly ) ); // Note this line! More work needs to be done here
show( disp ); // Result: disp = Dispatch({}, "Tall", "height", ScaleBox, {});上面的腳本非常繁忙,在弄清楚其餘部分後,我將尋找通過減少必要變量的數量來優化的方法,因為這是一個相當長的列表。
在腳本底部附近,有更多關於註釋的信息:ref_line needs to be inserted into curly BEFORE curly is inserted into disp. 很容易認為您可以這樣做:
insert( curley, ref_line );
但是,由於 ref_line 的內容包含在參數中,而不是函數中,因此 JMP 會出錯。一旦想出辦法解決這個問題,其他一切都應該很容易。我的下一個猜測是嘗試這樣的事情:
// Note: char( ref_line ) will cause JMP to error, because it's an argument
new_parse = expr( parse() );
insert into( new_parse, char( ref_line) );
// Then somehow
eval( insert into( curley, eval expr( eval( new_parse ) ) ) );
在了解如何將非字符類型參數插入另一個參數後,Graph Builder() 函數的其餘部分將很容易構建。 最後一部分是將所有內容作為表達式插入到 dt << New Script( "Visualization", ); 中,然後使用 eval expr() 和另一個 eval() (?) 使 JMP 成功執行代碼並將可視化插入 dt.
這是我發現的一些有趣的東西。當試圖將一個參數(非字符)插入另一個參數(字符)時,try() 幫助非字符變成一個字符串。然而,當我對此進行更多測試時,結果無法複製。此外,那些花括號很難插入任何東西。
Names default to here(1);
clear log();
// This block demonstrates, at a basic level, what I'm trying to do
printing = Expr( print() );
hello = "hello world";
insert into( printing, hello );
eval( printing );
show( printing ); // Result = printing = Print("hello world");
// Test run 1 - Works
new_parse1 = Parse( "Variable()" );
mytest1 = "X(:height)";
insert into( new_parse1, parse( mytest1 ) );
show( new_parse1, type( mytest1 ) ); // Result: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 2 - Doesn't work
new_parse2 = Parse( "Variable()" );
mytest2 = X(:height); // "Name unresolved"" error! X is not recognized
insert into( new_parse2, parse( mytest2 ) );
show( new_parse2, type( mytest2 ) ); // Intended: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 3 - Works
new_parse3 = Parse( "Variable()" );
try( mytest3 = X(:height) );
insert into( new_parse3, parse( mytest3 ) );
show( new_parse3, type( mytest3 ) ); // Result: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 4 - Doesn't work
curly = "{}";
new_parse4 = Parse( "Variable()" );
x_test = parse( "X()" );
some_list = { "one", "two", "three" };
insert into( x_test, eval( some_list[1] ) );
show( x_test ); // Result: x_test = X("one");
insert into( new_parse4, x_test ); // Containing within try() avoids error, but x_test not added into new_parse3
show( new_parse3 ); // Result: new_parse3 = Variable(); <-- Intended: new_parse3 = Variable(X("one"));
insert into( curly, new_parse4 );
show( curly ); // Intended: new_parse3 = {Variable(X("one"))};
// Other attempts - Doesn't work
variable1 = Variable(X("one"));
variable2 = eval insert( "{^variable1^}" );
variable3 = "{" || char( variable1 ) || "}";我相信你有很多額外的並發症。我相信你正在等待這樣的事情:
Names default to here(1);
clear log();
// Reference table
// Used to populate data in table script below for dt( big )
dt = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Set Values( { "Tall", "Short", "Thin" } ) ),
New Column( "Height tag", Numeric, Set Values( { 67.5, 60, 56 } ) ),
New Column( "color", Character, Set Values( { "medium dark green", "medium dark red", "purple" } ) )
);
// Example table
big = open( "$SAMPLE_DATA/Big Class.jmp" );
big << New Column( "Random", Numeric, <<SET each="" value=""></SET>你好,
我的任務是將一些可視化腳本編寫為表腳本。通常這很簡單。 粗略的部分是腳本運行時需要引用其他源的參考線。由於引用包含在兩個通常不接受外部變量的函數中,因此找出如何使用表達式操作來插入這些值目前超出了我的技能水平。 有許多障礙需要克服。
- 不能很好地接受外部變量的函數
- var1 = 1;
var2 = 2;
dt << 新腳本( “example”, print( var1 + var2 ) ); - 請注意,變量是在表腳本之外定義的。 這是一項要求,因為這些數字將從數據表中引用。
- 派遣()
- 使用不包含函數的表達式
- 示例 = expr( 新腳本() );
標題=“測試”;
插入(示例,標題); // 顯示(示例)= 新腳本(“測試”)
// 稍後在 x 軸中插入 cols 時,如示例的第 22 行...
x_empty = expr( X() );
x_cols = { :col1, :col2 };
插入( x_empty, x_cols[1] ); // 出錯,JMP 不知道 X() 是什麼 - 這告訴我,不知何故 X() 需要不被評估,但仍然允許項目插入,這就是名稱 expr() 和 expr() 之類的應該做的事情,但它們在這種情況下不起作用
示例腳本包含我想要完成的任務的簡化示例。 新生成的表中的標題和編號將在運行函數插入到 Big Class 之前插入到表腳本中。 我在腳本底部有一個基本示例。
Names default to here(1);
clear log();
// Reference table
// Used to populate data in table script below for dt( big )
dt = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
// Example table
big = open( "$SAMPLE_DATA/Big Class.jmp" );
// Plain example - vis added as table script * works *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), X( :age ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Dashed", "Medium Dark Green", "Tall", 1 ),
Add Ref Line( 60, "Dashed", "Medium Dark Red", "Short", 1 )}
)
)
)
);
// Needed info for below
vis_x = { :weight, :age };
vis_y = { :height };
// Modified example - vis added as table script * not working *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( vis_x[1] ), X( vis_x[1] ), Y( vis_y[1] ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( big:Height tag[1], "Dashed", "Medium Dark Green", big:Growth Label[1], 1 ),
Add Ref Line( big:Height tag[2], "Dashed", "Medium Dark Red", big:Growth Label[2], 1 )}
)
)
)
);
// Example: expression manipulations
var1 = 10; // represents some reference number, from somewhere
var2 = 1; // represents some reference number, from somewhere
expr_test = eval expr( expr(var1) + expr(var2) );
expr_begin = expr( New Script( "Var replacement" ) );
insert into( expr_begin, name expr( expr_test ) );
show( expr_begin );
eval( eval expr( big << expr( name expr( expr_begin ) ) ) ); // Script contains: 10 + 1
/* Notice how the table script "Var replacement" in big doesn't contain var1 & var2,
it contains the values they represent. This is what I want to do. */
close( dt, "No Save" );在社區論壇中搜索“參考線”會產生相當多的結果。 到目前為止,我發現的最接近的例子是下面的鏈接。
https://community.jmp.com/t5/Discussions/Is-there-a-way-to-automatically-draw-ref-lines-at-the-peak-of/mp/87721/highlight/false#M38710
https://community.jmp.com/t5/Discussions/Fill-color-for-multiple-reference-lines/mp/273205