When integrating R with Java with RCaller, I never get back any variable that is created within the script. There seems to be a fundamental missunderstanding how RCaller works. Isn't it that all the variables in the Environment can be parsed from Java? How?
@Test
public void test() {
RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable("/usr/bin/Rscript");
caller.runAndReturnResult("source('~/git/conjoint_it/src/main/r/a.R')");
System.out.println(caller.getParser().getNames());
}
a.R:
...
m3 <- mlogit(choice ~ 0 + seat + cargo + eng
+ as.numeric(as.character(price)),
data = cbc.mlogit)
su = summary(m3)
m3 #last line
this returns only [visible]
you can handle all of the variables defined in an environment with RCaller. Now we suppose you use the global environment (this is a special and the top level environment in which you declare variables out of a refclass or a function).
Results like this:
Here is the key point
so we are defining a variable to capture all of the variables defined in the global environment. as.list() function converts an environment object into a list. The second important point is to transfer this variable into the java by
You can see more examples about capturing specific variables rather than environments by visiting the blog page and the web page.