title: R integration with node JS
body: <p>I want to integrate R with node JS. I found out about a simple npm called <code>r-script</code> which allows r script to be run on node js.</p>
  
  <p>For those of you who don't know what r-script does the following node JS runs the <code>IntegrationTest.R</code> R script</p>
  
  <p>node JS code</p>
  
  <pre><code>var R = require('r-script');
  var out = R('/Users/JC/Documents/Programming/R/Tutorial/IntegrationTest.R')
  .data()
  .callSync();
  
  console.log(out);
  </code></pre>
  
  <p>IntegrationTest.R script</p>
  
  <pre><code>print('hello')
  </code></pre>
  
  <p>so above prints hello just fine when I run the node JS code.</p>
  
  <p>Then when I try the script below (the R script works on R studio by the way), it throws me error and says <code>Loading Required Packages : ape</code>.</p>
  
  <p>I thought maybe it doesn't know where to get the R package from so I specified the repository but it still throws me same error.</p>
  
  <p>Anyone who attempted to integrate R with node JS experience the same thing or know what's going on here?</p>
  
  <p>Thank you</p>
  
  <p>Node JS</p>
  
  <pre><code>var R = require('r-script');
  var out = R('/Users/JC/Documents/Programming/R/Tutorial/MoransI.R')
  .data()
  .callSync();
  
  console.log(out);
  </code></pre>
  
  <p>MoransI.R</p>
  
  <pre><code>if (!require("ape")) {
  install.packages("ape", repos="http://cran.rstudio.com/") 
  library("ape")
  }
  
  ozone &lt;- read.csv('/Users/JC/Documents/Programming/R/Tutorial/ozone.csv', sep=',', header=T)
  head(ozone, n=10)
  
  ozone.dists &lt;- as.matrix(dist(cbind(ozone$Lon, ozone$Lat)))
  
  ozone.dists.inv &lt;- 1/ozone.dists
  diag(ozone.dists.inv) &lt;- 0
  
  ozone.dists.inv[1:5, 1:5]
  
  Moran.I(ozone$Av8top, ozone.dists.inv)
  </code></pre>
  
  <p>I honestly think the only difference between the two R script is that the first doesn't load any package and the second loads a package.</p>