Did you read the JMP documentation that I cited above? You might find this white paper useful, too.
Here is an example of using R with JMP in a recent project of mine. I show two versions. The first uses matrices to transfer data between JMP and R.
Names Default to Here( 1 );
// make sure JMP can find the desired installed version of R
Set Environment Variable( "R_HOME", "C:\Program Files\R\R-4.1.3" );
// use Big Class from JMP Sample Data Folder
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
x = :height << Get As Matrix;
y = :weight << Get As Matrix;
Close( dt, No Save );
// connect to R session
R Init( );
// send JMP data as vectors
R Send( x );
R Send( y );
// use mcreg function in mcr package with entire data set
R Submit("
library( mcr )
mc <- mcreg( x, y, alpha = 0.05, method.reg = \!"PaBa\!", method.ci = \!"analytical\!", slope.measure = \!"tangent\!" )
print( mc )
parms <- getCoefficients( mc )
pred <- parms[1] + parms[2]*x
print( pred )
resid <- y - pred
print( resid )
");
// close R connection
R Term();
// select View > Log (Windows) or Windows > Log (macOS) to see results
The second versions uses the JMP data table instead. It becomes a data frame in R.
Names Default to Here( 1 );
// make sure JMP can find the desired installed version of R
Set Environment Variable( "R_HOME", "C:\Program Files\R\R-4.1.3" );
// use Big Class from JMP Sample Data Folder
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
x = :height << Get As Matrix;
y = :weight << Get As Matrix;
Close( dt, No Save );
// connect to R session
R Init( );
// send JMP data as vectors
R Send( x );
R Send( y );
// use mcreg function in mcr package with entire data set
R Submit("
library( mcr )
mc <- mcreg( x, y, alpha = 0.05, method.reg = \!"PaBa\!", method.ci = \!"analytical\!", slope.measure = \!"tangent\!" )
print( mc )
parms <- getCoefficients( mc )
pred <- parms[1] + parms[2]*x
print( pred )
resid <- y - pred
print( resid )
");
// close R connection
R Term();
// select View > Log (Windows) or Windows > Log (macOS) to see results
You can send individual commands to R or, as I illustrated, an entire R script as a character string. You can use all the JSL features for strings and expressions to create custom R scripts 'on the fly.'