node-Rstats icon indicating copy to clipboard operation
node-Rstats copied to clipboard

can I define and call R functions?

Open meonkeys opened this issue 10 years ago • 3 comments

Also, can I load other R libraries?

meonkeys avatar Apr 03 '15 01:04 meonkeys

Since you can execute any R code from inside node, this is certainly possible. Currently you could do both via the parseEvalQ method. For example, to load the xtable R library into the R session, one would execute R.parseEvalQ('library(xtable)'). To define a function which adds the value two to all elements of a vector, we could do R.parseEvalQ('add2 <- function(x){ x + 2}'). However, to call it you would have to manually create the appropriate R code as a string and then again invoke it via parseEval just like any other function. In the future, I will try to come up with a nicer way to call R functions. Hope that helps.

Planeshifter avatar Apr 08 '15 10:04 Planeshifter

It would be very useful to have methods to load and install packages. And to support DataFrames :-)

tecnocriollo avatar Sep 14 '15 02:09 tecnocriollo

And to support DataFrames

@psanchez1982 This works for me:

R.parseEvalQ("df = data.frame(x=1:2, y=3:4)");
var df = R.get("df");
console.log(df);
// result: [ { x: 1, y: 3 }, { x: 2, y: 4 } ]

stla avatar Sep 30 '16 11:09 stla