How to create an application using R functions<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hi all,
I would be very grateful for any help, as I am new to JMP I am struggling a bit!
I would like to create a tool (would that be an add in?) in JMP (that could be then used by others I need to work with) from functions I have written in R-code.
Is that possible? I have read that it is but I don't even know where to start.
I need this tool to ask the user to put in 3 file paths and let the R-functions use them.
Thank you for your help
Re: How to create an application using R functionsIn the end I used the Add-in builder (end of page 14 in the JMPer Cable Newsletter) which seems to have worked quite well and was very easy to do!
Re: How to create an application using R functionsIt could of course simply be that for the moment I only have the trial version of JMP 10...
I'll have the real thing end of next week, so I'll try again then.
Re: How to create an application using R functionsI'm stuck on step 3, nothing seems to be happening...
I must be doing something wrong:
I opened a new script and typed
registerAddin(
"com.myCompany.myAddin" ,
"C:/Users/.../Desktop/myAddinFolder"
);
and when I run it nothing happens,
I presume something is supposed to happen so that I can then proceed to step 4?
Thank you so much for all your help
Re: How to create an application using R functionsPage 14 of a recent JMPer Cable covers making Add-ins
http://jmp.com/about/newsletters/jmpercable/pdf/27_winter_2011.pdf
I think the instructions in the cable may be a little better than what I could come up with. I've been following them to the letter to create addins that anyone in my organization can install without having to have any drives mapped out or anything.
One thing I do in addition to the instructions in the Cable is that once I've registered the addin and I'm customizing my menu/toolbars, I hit the 'Change' button at the top and select the addin I'm currently making a menu/toolbar for and it saves the customization to the working folder.
Hope this helps.
Re: How to create an application using R functionsI've got things working, not exactly how I want just yet but a decent first draft anyway.
Do you think you could show me how to create a tool from the script ("the button on the toolbar")?
Thanks!
Re: How to create an application using R functionsYes, that works perfectly. Thanks!
Re: How to create an application using R functionsIf Names = {{"t1","t2"}}; try Names[1] - that should get the list nested inside the list.
Re: How to create an application using R functionsOk so the problem seems to be that in my script there are two "{" instead of just one...
I've just tested Names = {"t1","t2"} and Names = {{"t1","t2"}}
So I'll have to try and figure out a way to fix that.
Sorry for that!
Re: How to create an application using R functionsIt works perfectly with Names={"test1","test2","test3"};
But when I hover over Names in my script, it shows me:
Names
{ {"V1", "V2",
...............
I took that to mean that it did contain the list, and Tests is a list in R (I've even added the line Tests<-as.list(Tests) to be sure).
Is it maybe that there are too many items? Although I did put in parameters to make the window bigger but that didn't seem to make any difference.
Other than that I really don't know what I'm doing wrong, I've been at it for hours now...
Re: How to create an application using R functionsAre you sure that Names contains a list?
Try replacing the first line of code with Names={"test1","test2","test3"};
This will verify that the JSL part is working as you want, then you can look at what is coming back from the RGet function
Re: How to create an application using R functionsThanks Dave!
I've decided to go with List Box in the end as it corresponds better to what I need.
So I now have this:
Names = R Get(Tests);
nw = New Window("Test",<
V List Box(
Check Box(Names, <
H List Box(
Button Box("Ok", tname = Names << get text; cancel=-1;),
Button Box("Cancel",cancel=1;)
)
)
);
if(cancel !=-1, Stop(););
But for some reason, in my window I only have the first item of the list "Names" - any ideas of why that may be? I have checked Names and it does contain all of the thirty something items I have put into it so I really don't understand why this is happening...
Re: How to create an application using R functionsthe V List Box function receives ones or more display boxes, each separated by commas. So on the Check Box line replace the semicolon (;) with a comma (,).
-Dave
Re: How to create an application using R functionsThanks,
That's very nicely done, and very useful!
However, I'm having a problem and I can't seem to find the answer anywhere.
I've got a list of names and I would like to create a new window in which the user can pick one name.
I tried this:
Names = R Get(Tests);
nw = New Window("Test",<
V List Box(
Check Box(Names);
H List Box(
Button Box("Ok", tname = Names << get text; cancel=-1;),
Button Box("Cancel",cancel=1;)
)
)
);
if(cancel !=-1, Stop(););
I know I must be doing something wrong here but I just can't figure out what...
I was expecting to see a window with a list of check boxes and then "Ok" and "Cancel" underneath but all I've got is "Ok" and "Cancel".
I would be extremely grateful for any help.
Re: How to create an application using R functionsYou might find some useful stuff here
http://www.pega-analytics.co.uk/learning-zone/jmp-r-integration/
Re: How to create an application using R functionsWhoops! mewing@eastman.com
Re: How to create an application using R functionsIt comes up as ...
Mine is on there if you send me a blank e-mail then I can send you on the code
Re: How to create an application using R functionsAbsolutely, if you hover over my name, you should see my email address.
Re: How to create an application using R functionsThanks, I'm starting to get the idea
My R script is made up of 3 functions,
-read_table(file,n)
-Summary_Table(file1,file2,file3,n)
-Test_tables(file1,file2,file3,n,t)
I now see how to get n and t but how to I get the different files (the files being the ones the user has chosen beforehand, I used path = Pick File("Which file do you want?"); as you suggested)?
Could I e-mail you the R-script so that you can have a better idea of what I'm trying to do?
Re: How to create an application using R functionsYour questions aren't ridiculous, everybody was new once (except the people who invented it).
Let's say you have written a function in R like the following:
r6 <- 0
k <- 6
for(i in 1:100000){
x <- rnorm(k+1)
m.i <- 1
for(j in 2:(k+1)){
if(m.i==1&x>x[j-1]){m.i <- 1}else{m.i <- 0}
}
m.d <- 1
for(j in 2:(k+1)){
if(m.d==1&x
}
r6 <- r6+m.i+m.d
}
perc.ooc <- r6/100000*100
This is just a script that estimates the probability of getting six points in a row all increasing or decreasing from a random normal(0,1) distribution (it relates to some stuffI I'm doing now which is why I'm using it). Lets say I wanted to let a user change the 'k' value for this rule from 6 to anything of their choice. There are a couple ways I could approach this, but I'll just show one that uses all the tools above.
First, I have a dialog window that prompts the user for for the value:
nw = New Window("Value for k?",<
kval = k << Get();
Now I send that value to R:
rconn << Send(kval,R Name("k");
Now, in my R session (which is invisible to the user) there is a variable called 'k' with whatever value was specified by the user in the dialog box.
Now I want to run my code:
rconn << Submit("
r6 <- 0
for(i in 1:100000){
x <- rnorm(k+1)
m.i <- 1
for(j in 2:(k+1)){
if(m.i==1&x>x[j-1]){m.i <- 1}else{m.i <- 0}
}
m.d <- 1
for(j in 2:(k+1)){
if(m.d==1&x
}
r6 <- r6+m.i+m.d
}
perc.ooc <- r6/100000*100
");
Note, I removed the like k <- 6 from my code because I've already sent that information to R. Now, the final step is I want to get the percent out of control so:
percentOOC = R Get(perc.ooc);
I can now display this information in a new window:
nw = New Window("Results",Show Menu(0),Show Toolbars(0),Text Box("Percent out of control is " || Char(percentOOC) || "%"));
Now, all of this is stored in the JSL script file, so there is no need for an R script window to be open.
If you're still having issues, can you post the R script (either here or PM me, I can help you get it put together)?
As far as adding it as a button, that's pretty easy, but I'll post how to do that after we've got your script working.
Re: How to create an application using R functionsThank you for your help!
However I still have a couple of problems, as I said I am really new to this so there may be simple thing I am missing...
If I use this:
rconn << Submit("name.in.R <- " || Char(JMPvariable));
rconn << Submit("
output <- R.function(name.in.R)
sapply(output,mean)
");
Is "name.in.R" the name of the function I have written in R? If so then does that mean that everytime I want to use this tool in JMP, an R script window will also have to be open with the script for the function?
Or in that space should I be able to write out my whole function (by that I mean the full script for the function)? It doesn't seem to be working for me...
And once this script is written up in JMP, will I be able to add an icon to the toolbar so that all the others have to do is click and enter the files to see the graphs and tables?
Thank you so much for your help, and sorry again if my questions are ridiculous.
Re: How to create an application using R functions This is fairly easy to do. The first thing you need to do is create some sort of GUI in JMP that allows the user to input the 3 file paths. This can be done a couple of ways:
dir = Pick Directory("Where is the file stored?");
This will present the user with a directory browser to select the directory where a file with a consistent name will be stored.
OR
path = Pick File("Which file do you want?");
This will present the user with a file browser to select a specific file.
Next, you need to establish an R connection.
rconn = R Connect();
Now, you have two ways of passing information to R, the first is
rconn << Send(JMPvariable,R Name("name.in.R"));
OR
rconn << Submit("name.in.R <- " || Char(JMPvariable));
rconn << Submit("
output <- R.function(name.in.R)
sapply(output,mean)
");
The first way just sends a variable over and initializes it in R. The second way allows you to submit any R code you want (include the functions you've written).
To get things out of R
JMPvariable = R Get(name.in.R);
A couple of things to note - it takes JMP a little bit of extra time to send code to R - what might take a second in R to run will take several times longer when run through a JSL script. The nice thing though is that you can use JMP to make beautiful output that R just couldn't do.
If you have any follow-up questions, please ask, I'll subscribe to the thread.