Very much a novice-question here. I like to use JMP, and have some data in R that I'd like to import to JMP. I'm trying to use the JMP-to-R interface (first time scripting in JMP), and I don't really know what I'm doing. However, when I run the following JSL script, nothing happens;
test1 = Get R(test1);
I'm sure there's much more to it than this, but I'm really at a loss on how to proceed. If you have some suggestions for how I begin pulling data from R into JMP, I'd love to hear! I'm on a PC that just got upgraded to Windows 10, so something I was thinking (but have no idea if this is it) is that JMP can't find the location of my R installation. Again, this is my first venture into JSL scripting, so this is probably a beginner question, but I'm not really sure what I'm doing here. Thanks!
I agree with Jim. There is a lot of information in the documentation that will save you much confusion and wasted time. Many of the examples provide a good starting point for your own scripts.
That said, using R with JMP is not difficult. You must first call the R Connect() function to start R and establish a connection. The other R functions, such as R Get(), then work through this connection.
Thank you for your suggestions, Mark & Jim. I took a look at the Scripting Guide again and, unfortunately, am still confused. I ran the "Test Your Setup" script that they provide in the Scripting Guide, and it appears to work fine (so my concern that JMP wasn't able to find R seems to be unfounded). However, when I try to run the following script to pull a test dataframe from the R environment (that I called "test1")..
R Connect(); test1 = R Get(test1);
I get the following output from the log:
TKIntRJMP.R version 5.05
Warning: Error in eval(expr, p) : object 'test1' not found
I'm not really sure how to trouble-shoot this. I was unable to find a resolution in the Scripting Guide to this issue. Maybe my understanding of this is incorrect? My understanding was that the command R Get() would pull some object from R and return it in JMP. So if I had a dataframe created in the R environment, it would be pulled into JMP as a datatable.
Thanks for your advice!
Here is a short example from the Help > Scripting Index that might help get you started:
Names Default to Here( 1 ); R Init(); x1 = [1, 2, 3]; R Send( x1 ); x2 = R Get( x1 ); Show( x1, x2 ); R Term();
I might have set you in the wrong direction with R Connect().
You might need to run a R script to make sure that the data frame is available when you call R Get(). The example code for the R Get() opens a JMP data table called Big Class, sends it to R, then gets it back to JMP. Sending it to R made it an active data frame. What are you doing to make the data frame active in R?
Here is another example that might help, where a R script is run from JMP.
Names Default To Here( 1 ); R Init(); R Submit( "x <- rnorm(1000) hx <- hist(x, breaks=100, plot=FALSE) plot(hx, col=ifelse(abs(hx$breaks) < 1.669, 4, 2)) x <- rnorm (100) y <- x**2 + rnorm (100) summary(y)" ); Wait( 3 ); R Term();
You might need something like this example to be sure that the R data frame is available.
Hmm, maybe my data.frame in R isn't available for JMP to access? I'm not sure why, though. When I ran an example script from JMP, it was able to access a dataframe.
R Init(); R Submit( " L3 <- LETTERS[1:3] d <- data.frame(cbind(x=1, y=1:15), Group=sample(L3, 15, repl=TRUE)) " ); R Get( d ) << NewDataView; R Term();
When I create a dataframe in R, however, it seems like JMP can't access it. My R script is as follows:
test1 <- data.frame("x"=c(1,2,3,4),"y"=c(5,6,7,8))
The resulting data.frame is stored in the R "Global Environment", but when I try to access it with R Get(test1), it doesn't seem to recognize this.
Yes, I think that you have to submit the R code to make the data frame active in the session during the connection with JMP. This example creates a data frame 'from scratch' and stores it in variable d. The R Get() call can ask for it because it now exists in the R workspace. You might also open a file or get a data frame as a result of modeling in other cases, for example. The data frame does not exist in R unless you submit code to make it one way or another way.
Names Default to Here( 1 ); R Init(); R Submit( "L3 <- LETTERS[1:3] d <- data.frame(cbind(x=1, y=1:15), Group=sample(L3, 15, repl=TRUE))" ); dt = R Get( d ) << New Data View; R Term();
How do you create the data frame in R? Why do you think that it exists in R when JMP connects to it?
There are no labels assigned to this post.