java - 保留 - Eclipse 和 Java

标签 java r rserve

您好,我正在根据本网站上的说明设置储备。 http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/

但是在 Eclipse 中使用“eval”时出现错误

             double d[] = c.eval("rnorm(10)").asDoubles();

错误 - “RConnection 类型的方法 eval(String) 未定义”

JAR 已正确加载到构建路径中,并且 rserve 正在运行,但是我无法弄清楚为什么只有 eval 函数导致了问题。

除此之外,还导入...

   import org.rosuda.REngine.Rserve.RConnection;

导致错误 - “导入 org.rosuda.REngine.Rserve.RConnection 与同一文件中定义的类型冲突”

有谁知道为什么会出现这种情况吗?谢谢

所有进口:

import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;




 public class RConnection {
public int[] mean(String a[]) {

    setupR();        

    return null;
}

public void setupR(){

    try {

        /* Create a connection to Rserve instance running
         * on default port 6311
         */

        RConnection c = new RConnection();// make a new local connection on default port (6311)

        double d[] = c.eval("rnorm(10)").asDoubles();
        org.rosuda.REngine.REXP x0 = c.eval("R.version.string");
        System.out.println(x0.asString());

    } catch (RserveException e) {
        e.printStackTrace();
    } catch (REXPMismatchException e) {
        e.printStackTrace();
    }
}
}

最佳答案

通过使用import org.rosuda.REngine.Rserve.RConnection;,您需要使RConnection在本地命名空间中已知。 但是,您已经在本地定义了一个名为 RConnection 的类。

请重命名您的类RConnection,您应该能够导入org.rosuda.REngine.Rserve.RConnection

关于java - 保留 - Eclipse 和 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34383150/

相关文章:

java - Synth - 将背景设置为 JFrame

r - Shiny 的 ggplot 绘图画笔限制,x 轴作为日期

java - 保留异常: Handshake failed

r - 从 Rprofile.site 启动 Rserve

java - REXP as List 不返回输出

java SimpleDateFormat.parse 将 UTC 时间转换为亚洲/香港时间

c# - jaxb marshal 生成空文件

java - 有没有办法在用 Java 创建文件时将文件发送到 AWS S3 存储桶?

r - R 数据帧中的级别

emacs - 如何在 Emacs Speaks Statistics for R 中关闭自动替换