js-call-r
JavaScript call R function with a simple way.
Integrate JaveScript and R.
JavaScript passes JSON to R script, and get JSON from R script by js-call-r module.
Install
npm install --save js-call-r
Usage
const rscript = ; // Syncrscript; // Async, support Promise while callback is undefinedrscript;rscript;
Synchronous
const result = call;console;
Asynchronous
call;
Or
call;
Options
false
is default.
Result
If verboseResult
of Options is true
, call() or callSync() will return the following object.
If it is false
, the result will only include <return from R script>
part.
While any error
occurs, the result will be the following object.
R script template
Transcate JSON data between JavaScript and R, so input and output for R scripts have to convert to JSON format.
# json librarylibrary('rjson') # function to callsumFunc <- function (num1, num2){ sum(num1, num2)} # get arguments of cliargs <- commandArgs(trailingOnly = TRUE) # arguments to JSONjson <- fromJSON(args) # call functionret <- sumFunc(as.numeric(json$a),as.numeric(json$b)) # convert return of function to listoutput <- list(result = ret) # output JSONprint(toJSON(output));
Example
npm test
License
No License