I want to integrate R with node JS. I learned about simple npm called r-script , which allows you to run r script on node js.
For those of you who don't know what r-script is doing, the next node JS runs IntegrationTest.R R script
node js code
var R = require('r-script'); var out = R('/Users/JC/Documents/Programming/R/Tutorial/IntegrationTest.R') .data() .callSync(); console.log(out);
IntegrationTest.R script
print('hello')
so when printing node JS code over prints hello is just fine.
Then when I try the script below (R script runs on R studio, by the way), it gives me an error and says Loading Required Packages : ape .
I thought that maybe he does not know where to get the R package, so I pointed out the repository, but he still throws me the same error.
Anyone trying to integrate R with node JS is experiencing the same thing or know what is going on here?
thanks
node js
var R = require('r-script'); var out = R('/Users/JC/Documents/Programming/R/Tutorial/MoransI.R') .data() .callSync(); console.log(out);
MoransI.R
if (!require("ape")) { install.packages("ape", repos="http://cran.rstudio.com/") library("ape") } ozone <- read.csv('/Users/JC/Documents/Programming/R/Tutorial/ozone.csv', sep=',', header=T) head(ozone, n=10) ozone.dists <- as.matrix(dist(cbind(ozone$Lon, ozone$Lat))) ozone.dists.inv <- 1/ozone.dists diag(ozone.dists.inv) <- 0 ozone.dists.inv[1:5, 1:5] Moran.I(ozone$Av8top, ozone.dists.inv)
I honestly believe that the only difference between the two R scripts is that the first one does not load any package, and the second one loads the package.