R with node JS

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.

+7
source share
2 answers

I hope you found the answer earlier, but your problem is that you are not using needs , as recommended on the Github readme :

r- script

A simple little module to transfer data from NodeJS to R (and vice versa).

Data transferred from node is converted to a list and loaded into the R environment as an input variable. No special syntax in R is required. For better portability / reliability, it is recommended to download packages with needs (supplied with the module - no installation required).

An example using needs :

 import MASS package for isoMDS needs(MASS) 
+1
source

Do I need Rstudio? What about the R console, can it be used instead?

-1
source

Source: https://habr.com/ru/post/1264959/


All Articles