org.rosuda.REngine.Rserve.RserveException:从java运行R脚本时eval失败
我正在获取名为org.rosuda.REngine.Rserve.RserveException的rserveexpetion:eval在运行以下代码时失败org.rosuda.REngine.Rserve.RserveException:从java运行R脚本时eval失败,java,r,svm,Java,R,Svm,我正在获取名为org.rosuda.REngine.Rserve.RserveException的rserveexpetion:eval在运行以下代码时失败 import org.rosuda.REngine.REXPMismatchException; import org.rosuda.REngine.Rserve.RConnection; import org.rosuda.REngine.Rserve.RserveException; public class Temp { publ
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()
。从这里尝试回答:使用Try-catch语句查看实际的R错误。这是因为R函数myAdd()
没有通过读取源文件正确初始化。尝试下面的答案:使用Try-catch语句查看实际的R错误