Java/R Interface (JRI)

PNS picture PNS · Mar 1, 2012 · Viewed 7.7k times · Source

I want to call some R code from within Java, on a Linux machine that has R installed already, so the Java/R Interface (JRI) is needed.

However, I am not sure how to go about this.

The JRI homepage says that the package is bundled in rJava. So, I downloaded rJava-0.9.3.tar.gz from the rJava Files section, and unzipped it, getting (among other things) a lot of Java source files (and their corresponding classes) in the src/java folder, plus 2 JARs (JRIEngine.jar and REngine.jar) in the inst/jri folder.

The JRI Files section, though, in addition to the above 2 JARs, also includes JRI.jar and all three of these libraries are more recent than the 2 in inst/jri.

In addition, none of these 3 JARs includes the binaries for the classes found in src/java, which appear to be necessary for calling R from within Java.

Running "make all" in the java/src folder seems to just execute some tests and no JAR is produced.

I would expect that all necessary classes come bundled in JAR files, so that they could be easily added in the classpath and in IDE projects (e.g., in Eclipse).

How can I get to that point?

Answer

Simon Urbanek picture Simon Urbanek · Mar 1, 2012

Use install.packages("rJava") in R - that will install rJava which includes JRI. You'll get the same effect by using R CMD INSTALL rJava_0.9-3.tar.gz. Both are the documented ways to install R packages. Make sure you have JDK installed and configured R with Java support before. Once installed, you can ask R about the location of JRI with system.file("jri",package="rJava")

Note that in order to use JRI you will need to setup the environment properly (typically using R CMD) and set java.library.path to include the JRI location. You may want to scan the stats-rosuda-devel mailing list which is the canonical place to ask about rJava/JRI.