昨天我发现了以下线程,这让我调查了 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