Yes, this is a use case we use Renjin for as well. You will still need to create an evaluation Context
for writing data, but you don't have to load the base packages, so it shouldn't be expensive. At some point
in the near future I'm going to untangle the data classes (org.renjin.sexp.*) from the evaluator so that you
will have a lightweight library for doing this kind of data processing.
Here's a quick example of how this might work:
ListVector.NamedBuilder dataframe = new ListVector.NamedBuilder();
dataframe.add("x", new DoubleArrayVector(1,2,3,4,5,6));
dataframe.add("y", new DoubleArrayVector(6,5,4,3,2,1));
dataframe.setAttribute("class", new StringArrayVector("data.frame"));
PairList.Builder list = new PairList.Builder();
Context context = Context.newTopLevelContext(); // this is still necessary for the moment, but should not be expensive
FileOutputStream fos = new FileOutputStream("my.RData");
GzipOutputStream zos = new GzipOutputStream(fos);
RDataWriter writer = new RDataWriter(context, zos);
// run external R process:
// x <- compute.something(df)
// save("x", file="results.RData")
FileInputStream in = new FileInputStream("results.RData");
GzipInputStream zin = new GzipInputStream(in);
RDataReader reader = new RDataReader(zin);
PairList results = reader.readFile();
SEXP x = results.getElementByTag("x");
This code is off the top of my head so you may need to fix a few syntax errors!
On Tue, Oct 2, 2012 at 9:01 AM, Kevin <kevin....@gmail.com>
I just came across this very cool project while looking for Java/R interop. I'm curious if it is possible to read and write .RData files without spinning up a whole R environment. I'd like to take some simple java collections and write them to an .RData file for some offline processing by a native R process. When the computation is complete, I'd like to read in the .RData file again.
I've managed a trivial test case of creating an RDataReader and calling .readFile() which is promising. Before I go too far, is this a supported use case? Would it be possible for future builds of renjin produce a minimal RData serialization library for use in java apps?