0.1.1 • Published 3 years ago

node-r-runner v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

node-r-runner

Experimental

Node.js module for running R scripts

Installation

R needs to already be installed, and jsonlite R library needs to be installed.

yarn add node-r-runner or npm install node-r-runner

Usage

In an R file:

input[[1]] + input[[2]]

In node:

const { R } = require('node-r-runner')

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