Java/R Interface (JRI)

百般思念 提交于 2019-12-22 18:56:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9508626/java-r-interface-jri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!