Subscribe Bookmark RSS Feed

Problem scripting column switcher using variables

mikedriscoll

Community Trekker

Joined:

Jun 23, 2011

Hi, I'm having a problem with scripting the column switcher from column variables obtained from GUI display boxes.  My example here is with graph builder, but I tried another platform with similar results. I don't know if it is because of how I'm obtaining the column names (obj << get items()), so I've included all of that in the attached jsl.  What should happen is graph builder should load with no errors, column "Y" should be in the Y role, and then "Y" plus my two added dummy columns "temp" and "temp2" should be in the column switcher. But in the first argument of Column Switcher(), it seems to only like having typed text in there. If I type the text "Y" or ":Y" it works fine, but I haven't found a way to massage my column variable containing "Y" in a way that it will work. When I use the variable, it throws an error.

Here's a snippet of the code, and I've attached a stripped down script that will open up sample data, generate a self populated GUI (just click OK), and you can see how just typing the column names will work, but my many attempts with variables will not. Am I doing something wrong, or is it a bug? If so, is there a workaround? I'm using JMP 11.2.0.

Note, this snippet is shown for reference only. If you want to run it, run the whole attached file. yParamNames is a list containing the parameters to be plotted.  "Y" is the first column in this list.

    Graph Builder(

        Size( 570, 559 ),

        Variables( X( column(dtDataOrig,tempName[1]) ), Y( column(dtDataOrig,yParamNames[1]) ), Overlay( column(dtDataOrig, partIdName[1]) ) ),

        Elements(

            Line( X, Y, Legend( 13 ), Row order( 0 ), Summary Statistic( "Mean" ) )

        ),

        Column Switcher(

            //"Y",  // typing the text of the column name works

          

            // does not work

            //as column(dtDataOrig, Y),

            //as column(:Y),

            //as column(Y),

            //column(Y),

            //column(:Y),

            yParamNames[1],  //          <----  I would think this would work, and would be the most straightforward implmentation, but can't get it to accept a variable.

            yParamNames

        )

    );

Thanks,
Mike

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Try taking the column switcher out of the Graph Builder function and creating it using a message:

gb = Graph Builder(

  Size(...),
  Variables( ... ),

  Elements( ... )

);

     

Eval(Parse(Eval Insert("\[   

    gb << Column Switcher( ^yParamNames[1]^, ^yParamNames^ )

]\")));


The syntax of the last piece is not easy to explain in detail but it is easy to use.  It is using the same principle that Peter outlined but with a syntax that doesn't require escape sequences to build the string.


It helps to understand the sequence that you use to build this last piece of code.  You start with this pattern:


Eval(Parse(Eval Insert("\[   


]\")));

you write (or copy) your JSL code inside this pattern:


gb << Column Switcher( yParamNames[1], yParamNames )

To indicate that there are variables that need to be dynamically evaluated quote with a 'caret' symbol:  ^variable^



-Dave
4 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Sometimes variables don't work directly in JSL.  Build the graph builder code dynamically as a string that you know will work, and execute it with eval(parse()).

dt = open("$sample_data\big class.jmp");

str = "Graph Builder(

     Show Control Panel( 0 ),

     Variables( X( :weight ), Y( :height ) ),

     Elements(

           Points( X, Y, Legend( 1 ), Jitter( 1 ) ),

           Line Of Fit(

                X,

                Y,

                Legend( 4 ),

                Confidence of Fit( 1 ),

                Confidence of Prediction( 0 ),

                Degree( \!"Linear\!" ),

                Equation( 0 ),

                Root Mean Square Error( 0 ),

                R²( 0 )

           )

     )

)";

eval(parse(str));

mikedriscoll

Community Trekker

Joined:

Jun 23, 2011

Is this what you had in mind? I tried this and it still behaves the same way.

      str = "Graph Builder(

            Size( 570, 559 ),

            Variables( X( column(dtDataOrig,tempName[1]) ), Y( column(dtDataOrig,yParamNames[1]) ), Overlay( column(dtDataOrig, partIdName[1]) ) ),

            Elements(

                  Line( X, Y, Legend( 13 ), Row order( 0 ), Summary Statistic( \!"Mean\!" ) )

            ),

            Column Switcher(

                  //yParamNames[1],

                  :Y,

                  yParamNames

            )

      );";

     

      eval(parse(str));

Solution

Try taking the column switcher out of the Graph Builder function and creating it using a message:

gb = Graph Builder(

  Size(...),
  Variables( ... ),

  Elements( ... )

);

     

Eval(Parse(Eval Insert("\[   

    gb << Column Switcher( ^yParamNames[1]^, ^yParamNames^ )

]\")));


The syntax of the last piece is not easy to explain in detail but it is easy to use.  It is using the same principle that Peter outlined but with a syntax that doesn't require escape sequences to build the string.


It helps to understand the sequence that you use to build this last piece of code.  You start with this pattern:


Eval(Parse(Eval Insert("\[   


]\")));

you write (or copy) your JSL code inside this pattern:


gb << Column Switcher( yParamNames[1], yParamNames )

To indicate that there are variables that need to be dynamically evaluated quote with a 'caret' symbol:  ^variable^



-Dave
mikedriscoll

Community Trekker

Joined:

Jun 23, 2011

Thanks David, this works perfectly.  I had been wondering if I should try the Eval(Parse(Eval Insert())) technique, but I would not have thought of using it after creating the graph builder object first.

Thanks to PMroz as well for your input as well... This script was sort of your idea actually.  Last Discover Summit, I had asked about showing temperature characterization data in a scatter plot fashion, as a replacement for my excel scripts, and you had suggested graph builder with column switcher. Works wonderfully. Thanks!

-Mike