【问题标题】:org.rosuda.REngine.Rserve.RserveException: eval failed while running R script from javaorg.rosuda.REngine.Rserve.RserveException:从java运行R脚本时评估失败
【发布时间】:2017-11-21 13:04:22
【问题描述】:

我收到名为 org.rosuda.REngine.Rserve.RserveException 的 RserveExcpetion:运行以下代码时评估失败。

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

public class Temp {

public static void main(String a[]) {
    RConnection connection = null;

    try {
        /* Create a connection to Rserve instance running on default port
         * 6311
         */
        connection = new RConnection();

        /* Note four slashes (\\\\) in the path */
        connection.eval("source('F:\\testFiles\\svm.R')"); //Here getting the exception
        int num1=10;
        int num2=20;
        int sum=connection.eval("myAdd("+num1+","+num2+")").asInteger();
        System.out.println("The sum is=" + sum);

    } catch (RserveException e) {

        e.printStackTrace();

    } catch (REXPMismatchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}
}

如何解决这个问题

【问题讨论】:

    标签: java r svm


    【解决方案1】:

    这是因为 R 函数 myAdd() 没有通过读取源文件正确初始化。从这里尝试答案:Calling R from Java using RServe weird error 使用 try-catch 语句查看实际的 R 错误。

    【讨论】:

      猜你喜欢
      • 2016-10-28
      • 2020-09-16
      • 2018-09-22
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      相关资源
      最近更新 更多