问题描述
我想在已安装R的Linux机器上调用Java中的一些R代码,因此需要Java / R接口(JRI)。
但是,我不知道该怎么做。
说该软件包捆绑在中。所以,我从,并解压缩,获取(除其他外) src / java 文件夹中的许多Java源文件(及其相应的类),以及2个JAR(JRIEngine.jar和REngine.jar)在 inst / jri 文件夹中。
,除了上述2个JAR之外,还包括JRI.jar,所有这三个库都比 inst中的2个更新/ jri 。
此外,这3个JAR中没有一个包含src / java中找到的类的二进制文件,这些类似于调用R所必需的来自Java内部。
在 java / src 文件夹中运行make all似乎只是执行了一些测试,并且没有生成JAR。 / p>
我希望所有必要的课程捆绑在JAR文件中,以便可以在类路径和IDE项目中轻松添加它们(例如,在Eclipse中)。
我怎样才能达到这一点?
在R中使用 install.packages(rJava)
将安装包含JRI的rJava。使用 R CMD INSTALL rJava_0.9-3.tar.gz
可以获得相同的效果。两者都是记录的安装R包的方法。确保以前安装了JDK并使用Java支持配置了R.安装完成后,您可以向R询问有关JRI的位置 system.file(jri,package =rJava)
请注意,为了使用JRI,您需要正确设置环境(通常使用 R CMD
)并设置 java.library .path
包含JRI位置。您可能想要扫描stats-rosuda-devel邮件列表,这是关于rJava / JRI的规范地点。
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?
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.
这篇关于Java / R接口(JRI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!