|
本帖最后由 duandao 于 2012-11-16 17:15 编辑
Java 调用 R语言函数 异常,请各位同学看看,谢谢!
参考贴:
http://shao-fan.com/blog/use-rserve-in-java.html
代码和异常:
RService rService = new RService();
RConnection re = rService.startTransaction(); //开始独占工作空间
double[][] xx = new double[][]{{1,2},{3,4,5}}; //生成两个二维数组
double[][] yy = new double[][]{{6,7},{8,9,10}};
File tempFile = null;
try {
re.assign("x", xx.toString()); //给R的变量赋值
re.assign("y", yy.toString());
tempFile = File.createTempFile("test-", ".jpg"); //把图像生成到文件
String filePath = tempFile.getAbsolutePath();
re.eval("jpeg('" + StringEscapeUtils.escapeJava(filePath) + "')");
re.eval("qqplot(x,y)"); //绘图
re.eval("dev.off()");
} catch (IOException e) {
// logger.warn("Failed to create temp file", e);
} catch (RserveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
rService.endTransaction(); //退出时一定要关闭此工作空间
}
异常:
org.rosuda.REngine.Rserve.RserveException: eval failed, request status: error code: 127
at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:234)
at com.taobao.relationrecommendadmin.app1.module.screen.TestAverage.main(TestAverage.java:502)
|
|