Renjin IOException在加载包Rweka时,找不到函数'.jfield'

时间:2017-07-17 12:36:01

标签: java package ioexception renjin

我正在尝试在Java程序中执行R脚本,所有依赖项都是用Maven安装的,但问题仍然存在。

在我修复问题的研究中,我发现jfield是rJava提供的函数,但我不确定rJava(Renjin包)是否实现了它。

¿有没有办法检查这个? ¿或者我错过了什么?

我的程序使用这些库,全部由Renjin支持:

  • rJava
  • RWeka
  • RWekajars

我正在通过Maven使用betadriven公共回购来安装它们。 这是主要的课程:

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'

提前致谢!

1 个答案:

答案 0 :(得分:0)

Renjin还没有完全支持rJava包。似乎缺少的一件事是.jfield的包装器。您可以在此处找到兼容性层:

https://github.com/bedatadriven/renjin-rjava/blob/master/src/main/R/rJava.R

拉请求欢迎!