RCaller handles results as list objects. Since R environments are list s, they can easily be converted to R lists (Visit the previous blog post on R list here).
Here is an example of RCaller on getting all variables that are created in the run time in R side.
package rcallerenvironments;
import rcaller.RCaller;
import rcaller.RCode;
public class RCallerEnvironments {
public static void main(String[] args) {
RCaller rcaller = new RCaller();
RCode code = new RCode();
rcaller.setRscriptExecutable("/usr/bin/Rscript");
code.addRCode("a <- 3");
code.addRCode("b <- 10.45");
code.addRCode("d <- TRUE");
code.addRCode("avector <- c(9,6,5,6)");
code.addRCode("allvars <- as.list(globalenv())");
rcaller.setRCode(code);
rcaller.runAndReturnResult("allvars");
System.out.println(rcaller.getParser().getNames());
try {
System.out.println(rcaller.getParser().getXMLFileAsString());
} catch (Exception e) {
System.out.println("Error in accessing XML");
}
}
}
Have a nice read!