cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
juliagong
Staff (Retired)
Getting started with the JMP to R Interface

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:

//initializes the R interfaces
R Init();

//send data to R
R Send(/*name of JMP object you want to send to R, i.e. data table, list, matrix, string, or numeric*/);
//or
R Send File(/*path to the file you want to send here, as a string*/);

//perform calculations in R
R Submit(/*code you want to execute in R here, as a string*/);
//or
R Submit File(/*path to the file that contains the R code you want to execute*/);

//return data from R
varName = R Get(/*name of object you want to return from R*/);

//terminates the R interfaces
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(/*list of R input var names*/, /*list of R output var names*/, "\[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(/*name of R variable that contains data table*/) << 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(/*name of R variable that contains list with values*/);
dt << New Column(/*name of new column*/, /*column data type, e.g. Character, Numeric*/, Values(varName));

 

If you want to display the most recently produced R plot, you can use:

R Get Graphics(/*either png or jpg*/);

 

To view this image in a JMP window, use:

New Window("My Plot", R Get Graphics(/*either png or jpg*/));

 

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.

Last Modified: Sep 8, 2017 1:04 PM