首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RCaller抛出java.io.IOException/ExecutionException

RCaller抛出java.io.IOException/ExecutionException
EN

Stack Overflow用户
提问于 2017-06-05 14:28:40
回答 1查看 121关注 0票数 2

当我想通过RCaller运行一些代码时,Java会抛出以下异常:

代码语言:javascript
复制
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.

这是我的密码:

代码语言:javascript
复制
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,如下所示:

代码语言:javascript
复制
rscript =  "\"" + rscript +  "\"";
r =  "\"" + r +  "\"";

它也没有起作用

编辑2:

当我尝试生成这样的情节时:

代码语言:javascript
复制
rCode.addRCode("plot(func)");

Java仍然抛出一个异常,但也会生成一个pdf,其中包含图中的内容。

Also...I´m慢慢地放弃了R...is,还有另一种方法从一个数学函数中计算积分,该函数在Java中作为字符串给出?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-01 18:56:06

你可以用极大值对定积分进行数值优化,也可以用符号优化。例如

代码语言:javascript
复制
integrate(2 * x, x)

返回x^ 2。你可以定义数值计算的下界和上界(定积分的近似)。您可以使用几个选项调用可执行文件maxima。您可以在文本文件中以及命令shell上的字符串中发送积分(当然,任何其他数学操作,包括限制和派生)。例如

代码语言:javascript
复制
maxima -q -r "integrate(2 * x, x);"

计算括号之间给定的积分,并将结果返回到标准输出。

祝好运。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44371257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档