I worked a lot with the JMP to R interface when building my JMP add-in, the JMP to R Custom Add-In Builder. So, if you want to learn how to get started with the JMP to R connection using JSL, you’ve come to the right place!
I’m an advocate for learning through examples rather than memorizing APIs, so let’s start with the example of roundtripping data through R and back to JMP. You will need to send data from JMP to R, perform operations in R, and return the results back to JMP. The backbone of your script should thus look like this:
R Init();
R Send();
R Send File();
R Submit();
R Submit File();
varName = R Get();
R Term();
Or, perhaps you’d like to do it all in one line, which is equivalent to R Send() for your variable names one by one, R Submit() for your code, and R Get() for R variables one by one:
R Execute(, , "\[your R code to submit]\");
One common question I’ve seen is, ‘what is the difference between R Send() and R Submit()?’
R Send() sends a data structure over to R — the five options are data table, list, matrix, string, and numeric.
R Submit(), by contrast, submits R code as a string to R that you want to execute. You can write the code as a string if it does not contain quotation marks or escape it by using “\[ code ]\”.
Once you have this backbone, one question remains: How do you get the R output in a format you can use?
The answer: It depends.
If you want to open up a data table that you retrieved from R, you can use the following command:
R Get() << new data view;
This opens up the data table in JMP.
If you want to append a column in an existing JMP data table, you can use:
varName = R Get();
dt << New Column(, , Values(varName));
If you want to display the most recently produced R plot, you can use:
R Get Graphics();
To view this image in a JMP window, use:
New Window("My Plot", R Get Graphics());
There are other output options as well, some of which are covered in this Mastering JMP Webcast.
One very important note to make: when performing operations such as R Get(), the R variable name must be the name as a JSL expression (i.e. not a string). R Get(“var”), which is incorrect, is not equivalent to R Get(var), which is correct.
Finally, one issue I ran into when using the JMP to R interface was that I relied on user input to determine the parameters for these functions. In this case, I would use Eval(Parse()) to run these JMP to R interface commands. For example:
Eval(Parse(varName || " = R Get(" || userInputValue || ");"));
or
Eval(Parse("dt << New Column(userInputForColumnName, " || userInputForColumnType || ", Values(" || stringNameOfListVariable || "));"));
Other JMP to R functions beyond these (R Connect(), R Control(), etc.) can be found in the Scripting Index.
Best of luck! I’d love to hear your thoughts about the JMP to R interface below in the comments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.