JMP find RHi there,
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!
Re: JMP find RI spoke to JMP Support about this topic; unfortunately, a user isn't able to pull a dataframe from R into JMP the way I was enquiring. From JMP Support:
JMP does not interact with R in this manner. When JMP initializes R, it starts a new session (environment). That session is completely isolated from R meaning, if you were to start a new R session, JMP would not recognize any of the environment variables (global or local). This is why your R data frame is unknown to JMP.
There are a few ways to pull data from R into JMP, but they essentially all require that the dataframe in R is "created" by running a script through the JMP Scripting dialog box. I've been doing option #3 (having R write the dataframe to a csv file, and then opening the csv file with JMP), but option #2 is intriguing. When I tried, this, unfortunately, I ran out of memory on my computer, so this may not be a viable option for extremely large dataframes. These were the suggestions from JMP Support:
1. Use JMP's R Submit () to create the data frame. The use R Submit () and R Get () to bring the data frame into JMP. This is probably the mostly commonly used approach.
2. Use JMP's R Submit () to load the data frame via R and bring it back to JMP.
3. Lastly, you can also save the data frame from R as a CSV and open it in JMP using JSL's open function.
Re: JMP find RPlease post their answer here. New territory!
Re: JMP find RThanks for trying this out on your end, Mark! I'll reach out to Technical Support to see what they have to say on this.
Re: JMP find RI just tried using a connection but it did not fare any better.
I have never encountered this situation before. I have always sent what I need to R, run R scripts, returned what I want, and move on in JMP.
I am not convinced that it is not possible. I recomment that you contact JMP Technical Support (support@jmp.com) and ask them for help.
Re: JMP find RHmm, maybe what I was wanting to do won't work in this instance?
I had a data.frame that was already in the R Global Environment (I/other people had worked on it in R), and I wanted to pull it into JMP. However, from my understanding of our conversation, I would need to run the entire R script in the JMP Script dialog box in order for JMP to "see" the data.frame. Is this correct?
Or maybe there's another step I've missed here. If I've already created a data.frame in R (and it is now in the R 'Global Environment), it's still not visible to JMP. But can it become visible to JMP? In R, I've run the following command:
test1 <- data.frame("x"=c(1,2,3,4),"y"=c(5,6,7,8))So now "test1" is in the R Global Environment. But for some reason JMP still can't "see" it? Maybe there's something I can do to make this data.frame visible to JMP without having to rerun the R script through the JMP Script dialog box?
Re: JMP find RHow do you create the data frame in R? Why do you think that it exists in R when JMP connects to it?
Re: JMP find RYes, 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();Re: JMP find RHmm, 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.
Re: JMP find RYou 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.
Re: JMP find RHere 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().
Re: JMP find RWhat did you store in the variable named test1?
Re: JMP find RThank 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
Unknown
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!
Re: JMP find RI 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.
Re: JMP find RThe first thing you should do is to read the section "Working with R" in the Scripting Guide section, Extending JMP
Help==>Books==>Scripting Guide