java - Rcaller 将 q 字符添加到 StringBuffer 的末尾

标签 java r rcaller

我正在使用 RCaller 从 Java 调用 R。请参阅以下 Java 代码:

RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable("/usr/bin/Rscript");
caller.cleanRCode();

String x = "is.installed <- function(mypkg){ \n" +
               "is.element(mypkg, installed.packages()[,1])\n"+
           "}\n" +
           "is.installed(\"bbmle\")";
StringBuffer s = new StringBuffer(x);
code.setCode(s);

System.out.println(x);
caller.setRCode(code);
caller.redirectROutputToConsole();
caller.runOnly();

这是 Java 输出。请注意 Rcaller 如何决定在 R 代码末尾添加一个 q(请参阅下面输出中的倒数第二行)。这是怎么回事?请注意,当我打印输出时,那里没有 q

is.installed <- function(mypkg){ 
is.element(mypkg, installed.packages()[,1])
}
is.installed("bbmle")
Error:Error: unexpected symbol in "is.installed("bbmle")q"
Error:Execution halted

最佳答案

RCaller 发送

q("yes")

命令R(在RunOnly()方法中),但是当你忘记在代码末尾放回车符时,并不是所有的R代码都可以发送到R(只有q部分被发送)发送)。使用

is.installed(\"bbmle\")\n

相反。

关于java - Rcaller 将 q 字符添加到 StringBuffer 的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21515155/

相关文章:

java - 将绘图从 R 流式传输到 Java,而不保存绘图

java.lang.NoClassDefFoundError : rcaller/RCaller in java-ee

Java 在窗口边界下绘制图形

r - 跳过 travis-ci 中某些操作系统和版本的组合

r - igraph (R) 中仅在根和终端顶点上添加标签?

java - R 和 Java 之间的桥梁错误

java - AXIS2 客户端返回带有空值而不是属性的对象

java - 在 WebSphere Application Server 中升级 JavaMail

java - OpenCSV CSVWriter 在文件末尾添加空行

r - 防止 rgl 在包示例中打开窗口