1

我正在使用 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 如何决定q在 R 代码的末尾添加一个(请参见下面输出中的倒数第二行)。这是怎么回事?请注意,当我打印输出时,那里没有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
4

1 回答 1

0

RCaller 发送一个

q("yes")

命令到 R (在 RunOnly() 方法中),但是当您忘记在代码末尾放置回车时,并非所有 R 代码都可以发送到 R (仅发送 q 部分)。利用

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

反而。

于 2014-04-13T13:56:09.613 回答