When I want to run some code through RCaller, Java throws the following exception:
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.
This is my code:
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]));
}
I checked my R installation and it seems to be fine
Edit:
I also tried concatenating rscript and r with "\"" like so:
rscript = "\"" + rscript + "\"";
r = "\"" + r + "\"";
And it didn´t work either :(
Edit 2:
When I try generating a plot like this:
rCode.addRCode("plot(func)");
Java still throws an exception but also generates a pdf with the plot inside
Also...I´m slowly giving up on R...is there another method of calculating integrals from a mathematical function given as a string in Java?