I’m trying to do some work between java and r (using some of the cross-correlation tools and other stats functions) and am trying to use the JGR package. I’ve spend a decent amount of time looking at the documentation and am having some difficulty figuring out how this JGR package works and even what its purpose is. A few questions:
1) Where do I actually write the code? In RGUI, in Eclipse, in some other console I have yet to experience?
I start by starting JGR:
> JGR()
Copy the following into WordPad and save as "jgrLaunch.bat"
set R_HOME=C:\PROGRA~1\R\R-214~1.0
set R_LIBS=C:\Users\~\Documents\R\win-library\2.14
set R_LIBS_USER=C:\Users\~\Documents\R\win-library\2.14;C:\Program Files\R\R-2.14.0\library
jgr-1_62.exe --rhome=C:\PROGRA~1\R\R-214~1.0 --libpath=C:\Users\~\Documents\R\win-library\2.14
Starting JGR ...
>
When I drop examples from the reference manual into R I get the following:
> jgr.addMenu("Workspace")
jgr.addMenu() cannot be used outside JGR.
> jgr.addMenuItem("Workspace","Browse","ls()")
jgr.addMenuItem() cannot be used outside JGR.
> jgr.addMenuSeparator("Workspace")
jgr.addMenuSeparator() cannot be used outside JGR.
> jgr.addMenuItem("Workspace","Browse (pos=2)","ls(pos=2)")
jgr.addMenuItem() cannot be used outside JGR.
> menus <- jgr.getMenuNames()
jgr.getMenuNames() cannot be used outside JGR.
> index <- which(menus=="Packages & Data")
> if(length(index)==0) index <- 1
> jgr.insertMenu("User menu",index)
jgr.insertMenu() cannot be used outside JGR.
> jgr.addMenuItem("User menu","A good place for user generated menus is","print(’before Packages & Data’)")
jgr.addMenuItem() cannot be used outside JGR.
But when I put it into eclipse there are things like <- that seem out of place.
2) Does anyone have any actual code? I usually can figure this stuff out with a few code examples but haven’t been able to track any down.
3) Any suggestions for a way that might be better/easier (ie different packages or setups)?
Any suggestions?
JGR is Java GUI for R and you run it by double-clicking on the JGR icon — which you download from http://rforge.net/JGR/web-files/jgr-1_62-x64.exe (64-bit) or http://rforge.net/JGR/web-files/jgr-1_62.exe (32-bit). What you loaded in R is merely the supporting R package and you ran it in Rgui, not in JGR (hence the errors).
JGR itself uses JRI (Java/R Interface) from rJava to load R into the Java process. If you are interested in using R from Java you can do the same. The API is documented in http://rforge.net/Rserve/doc/
You can use exactly the same API on the Java side with Rserve which uses a client/server model of communication.
You can have a look at the stats-rosuda-devel mailing list which is a place to discuss JGR, rJava, JRI, Rserve etc.