当我想通过RCaller运行一些代码时,Java会抛出以下异常:
Exception in thread "JavaFX Application Thread" com.github.rcaller.exception.ExecutionException: Can not send the source code to R file due to: java.io.IOException: The pipe is being closed Maximum number of retries exceeded.这是我的密码:
protected void initialize(){
if (!System.getProperty("os.name").contains("Windows")){
rscript = rscript.replace("\\","/");
r = r.replace("\\","/");
}
out.println(rscript + "\n" + r);
caller = RCaller.create(RCallerOptions.create(rscript,r,FailurePolicy.RETRY_1,500,500,RProcessStartUpOptions.create()));
}
private void calculateIntegral(String newValue){
RCode rCode = RCode.create();
rCode.addRCode("func <- function (x) (" + newValue + ")");
rCode.addRCode("x <- integrate(func," + from.getValue() + "," + to.getValue() + ")");
caller.setRCode(rCode);
caller.runAndReturnResult("x"); <- This is where I get the Exception
value.setText(String.valueOf(caller.getParser().getAsDoubleArray("x")[0]));
}我检查了我的R装置,看上去很好
编辑:
我还尝试用“\”连接rscript和r,如下所示:
rscript = "\"" + rscript + "\"";
r = "\"" + r + "\"";它也没有起作用
编辑2:
当我尝试生成这样的情节时:
rCode.addRCode("plot(func)");Java仍然抛出一个异常,但也会生成一个pdf,其中包含图中的内容。
Also...I´m慢慢地放弃了R...is,还有另一种方法从一个数学函数中计算积分,该函数在Java中作为字符串给出?
发布于 2018-10-01 18:56:06
你可以用极大值对定积分进行数值优化,也可以用符号优化。例如
integrate(2 * x, x)返回x^ 2。你可以定义数值计算的下界和上界(定积分的近似)。您可以使用几个选项调用可执行文件maxima。您可以在文本文件中以及命令shell上的字符串中发送积分(当然,任何其他数学操作,包括限制和派生)。例如
maxima -q -r "integrate(2 * x, x);"计算括号之间给定的积分,并将结果返回到标准输出。
祝好运。
https://stackoverflow.com/questions/44371257
复制相似问题