I am trying to setup a simple connect between a NodeJS application and an R-script.
So far I've managed to set up the basic connection and the running of the cript, by using r-script
(found on npm).
However, I am not able to pass a simple json to the R so that it can be converted to a dataframe using jsonlite
.
NodeJS Code:
var R = require("r-script");
var out = R("script.R")
.data({"Name" : "Mario", "Age" : 32, "Occupation" : "Plumber"}, {"Name" : "Peach", "Age" : 21, "Occupation" : "Princess"}, {}, {"Name" : "Bowser", "Occupation" : "Koopa"})
.callSync();
console.log(out);
script.R:
library("jsonlite")
mydf <- fromJSON(input[[1]])
This gives the output:
'Argument 'txt' must be a JSON string, URL or file.'
I have tried removing the indexation of the vector (and give the full list to the fromJSON) but it also doesn't work.
Has anyone sucessfully passed JSON to an R script with this npm module?
Thanks in advance!
EDIT: Also, if place the JSON between "'", it gives me "trailing errors" in spaces, and if they are removed, on the { char.