I'm trying to create a data frame in R taking the data from an ArrayList in Java.
The code below seems to be the official JRI test suite (see this link) however it doesn't even compile, for example in the first statement RList doesn't have a put method and REXP.createDataFrame method doesn't exist.
Is there any updated example of REXP.createDataFrame
? Couldn't find a concrete/functional example online. Also, couldn't find any JRI documentation.
String[] Rargs = {"--vanilla"};
Rengine re = new Rengine(Rargs, false, null);
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
RList l = new RList();
l.put("a",new REXPInteger(new int[] { 0,1,2,3}));
l.put("b",new REXPDouble(new double[] { 0.5,1.2,2.3,3.0}));
re.assign("z", REXP.createDataFrame(l));
REXP x = re.parseAndEval("z");
System.out.println(" z = " + x);
UPDATE
I found out that there are two REXP
classes org.rosuda.JRI.REXP
and org.rosuda.REngine.REXP
, the latter has the method createDataFrame(l)
, however the assignment doesn't work. How to assing a data frame to an R variable?