Question

I am using RCaller to call R from Java. See the following Java code:

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();

Here is the Java output. Notice how Rcaller has decided to add a q (see the 2nd to last line in the output below) to the end of the R Code. What's this all about? Note that when I print the output, there is no q there.

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
Was it helpful?

Solution

RCaller sends a

q("yes")

command to R (in RunOnly() method), but when you forget to put an carriage return at the end of the code, not all of the R codes can be sent to R at all (only the q part is being sent). Use

is.installed(\"bbmle\")\n

instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top