Module for running R scripts from node
Based on r-script by joshkatz. Decided to re-write this project because I need similar functionality and that project seems unmaintained.
R needs to already be installed, and jsonlite R library needs to be installed.
yarn add @fridgerator/r-script
or npm install @fridgerator/r-script
In an R file:
input[[1]] + input[[2]]
In node:
const { R } = require('@fridgerator/r-script')
let r = new R('./add.R')
// optionally pass an options object used in child_process spawn calls
let r = new R('./add.R', {env: {PATH: '/bin:/location/to/R/bin'}})
// data is converted to a list variable `input` in the R script
r.data(2, 3)
// call the script async
r.call()
.then(response => response === 5) // true
.catch(e => console.log('error : ', e))
// OR call the script async
let result = r.callSync() // could raise an exception
result === 5 // true