我正在尝试在 Java 程序中执行 R 脚本,所有依赖项都使用 Maven 安装,但问题仍然存在。
在我解决问题的研究中,我发现 jfield 是 rJava 提供的一个函数,但我不确定 rJava(Renjin 包)是否实现了它。
¿ 有没有办法检查这个?¿ 或者我错过了什么?
我的程序使用了 Renjin 支持的所有库:
- rJava
- 威卡
- RWekajars
我正在通过 Maven 使用 beta 驱动的公共 repo 来安装它们。这是主要课程:
package org.dfont.renjin;
import org.renjin.script.RenjinScriptEngineFactory;
import javax.script.ScriptEngine;
public class TryRenjin {
public static void main(String[] args) throws Exception {
// create a script engine manager:
RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
// create a Renjin engine:
ScriptEngine engine = factory.getScriptEngine();
// ... put your Java code here ...
if(engine == null) {
throw new RuntimeException("Renjin Script Engine not found on the classpath.");
}
else{
engine.eval(new java.io.FileReader("/home/dfont/renjinTest/pruebaCalculo.R"));
}
}
}
这里是我的 pom.xml,
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dfont.renjin</groupId>
<artifactId>renjin</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>rJava</artifactId>
<version>0.9-8-renjin-5</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>RWekajars</artifactId>
<version>3.9.1-3-b3</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>RWeka</artifactId>
<version>0.4-34-b5</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>bedatadriven</id>
<name>bedatadriven public repo</name>
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>org.dfont.renjin.TryRenjin</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
运行程序时的第一行输出:
Exception in thread "main" org.renjin.eval.EvalException: IOException while loading package org.renjin.cran:RWeka: could not find function '.jfield'
提前致谢!