A simple little module for passing data from NodeJS to R (and back again).
Data passed from node is converted into a list and loaded into the R environment as the variable input
. No special syntax in R is needed. For better portability/reliability, it's recommended to load packages with needs
(comes packaged inside the module — no installation required).
npm install @maki-people/r-script
npx ts-node example/ex.ts
// [ { group: '(40,55]', rating: 46.7143, advance: 41.1429 },
// { group: '(55,70]', rating: 64.6154, advance: 41.9231 },
// { group: '(70,85]', rating: 77.2, advance: 45.5 } ]
npm run build
npm run test
R(path)
Creates an instance of the R class that will source the R script specified by path.
R.data(...)
Adds data to the object. You can give any number of arguments of different types.
R.execute(timeout)
Calls R. Any previously supplied data is stringified into JSON and passed to R, where it's converted into a list and loaded into the R environment as the variable input
.
The promise resolves the R script output or reject any error.
If any timeout in ms is provided, the R script process will be killed after the timeout delay.