gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:37 24 4
gpt4 key购买 nike

我正在使用 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/

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