Planeshifter / node-Rstats

[UNMAINTAINED] An interface for node.js to statistical programming language R based on the fabulous Rcpp package
GNU General Public License v2.0
58 stars 16 forks source link

Any way to retrieve an image? #3

Closed PaulMougel closed 9 years ago

PaulMougel commented 9 years ago

I'm using R to create plots and I want to retrieve the resulting PNG or PDF file in node. The idea here is to provide an HTTP API that can launch an R script and return an image computed by R.

Here is a rough example:

var R = require('rstats');
var util = require('util');
var h = new R.session();
h.parseEvalQ('require("ggplot2");');
h.parseEvalQ('p <- qplot(carat, price, data = diamonds);');

Now, I'd like to export a PNG file and send it to node. But ggsave doesn't seem to be able to write the content of the file to a variable. I tried using var content = h.get('p') but it failed:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Error evaluating: toJSON(p);

Of course I could use ggsave to save to a temporary file which node could read, but I'm looking for a way to do this without even touching the hard drive… I'm not really R-savvy; does anyone have any idea on how to achieve this?

PaulMougel commented 9 years ago

Closing this as using a temporary file is in fact what RInside's creator did with his Wt application (see source here); this will do just fine for us at the moment.