0

I am trying to connect R from java using RCaller and here is my code

RCaller caller = new RCaller();
RCode code = new RCode();
caller.cleanRCode();
caller.setRscriptExecutable("C:/Program Files/R/R-3.0.2/bin/Rscript.exe");
code.addRCode ("source(\"D:/Data Mining workspaces/Workspace/CQpackage/First_try.R\")");
code.addRCode("myinput()");
caller.setRCode(code);
caller.runAndReturnResult("Done");

First_try.R contains a function defnition and the function is called myinput()

When i run this i am getting this error, i am not able to understand the reason. Please HElp

rcaller.exception.RCallerExecutionException: Can not run C:/Program Files/R/R-3.0.2/bin/Rscript.exe. Reason: java.io.IOException: Cannot run program "C:/Program": CreateProcess error=2, The system cannot find the file specified
at rcaller.RCaller.runAndReturnResult(RCaller.java:393)
Magic
  • 505
  • 2
  • 6
  • 19

3 Answers3

2

Try using runOnly() instead of runAndReturnResult().

I suppose that runAndReturnResult("done") will run your code and return the value in the variable "done" which hasn't been initialized.

So, just use runOnly() which would just run your code. If you need to view your result, try redirecting your result to either any stream or console.

0

Try to escape the space in the path. From the error it looks like that could be a problem. Also check out this question: Error under bridge between R and Java

Community
  • 1
  • 1
  • I tried escaping by doing Program\ files but its giving me illegal escape sequence error. – Magic May 07 '14 at 07:10
0

Please change the line

caller.setRscriptExecutable("C:/Program Files/R/R-3.0.2/bin/Rscript.exe");

by

caller.setRscriptExecutable("C:\\Program Files\\R\\R-3.0.2\\bin\\Rscript.exe");

in Windows. It seems it is a Java issue, not the one about RCaller.

jbytecode
  • 681
  • 12
  • 29