gpt4 book ai didi

java - org.rosuda.REngine.Rserve.RserveException : eval failed while running R script from java

转载 作者:太空宇宙 更新时间:2023-11-04 11:23:36 25 4
gpt4 key购买 nike

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

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();
}
}
}

如何解决这个问题

最佳答案

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

关于java - org.rosuda.REngine.Rserve.RserveException : eval failed while running R script from java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44628442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com