rscripts
Simple connector between nodejs and R
prerequisite
$ node -v # recommanded version > 10 $ Rscript --version # Rscript commands exist in PATH
API
-
new R(option), option:
{silence: false}
silence: silence
print
/cat
... globally. -
async exec(path, ...args)
path: file path
args: appending arguments in command line
Notice
exec
is the final output of R, mass print
/ cat
/ ... or other logging methods at the same time may clog the message pipe, thus better use Sys.sleep()
before output the final result
- The result of process.env
, passing data through ...args
is highly UNRECOMMANDED, because it will transfer data through command line, and the program will sanitize the input first for security reasons, but such method destroys the data integrity, i.e. the program is going to replace '
with "
- exec(path, ...args): the proper way to pass data between application is through example
JS:
const R = ;var r = silence: false ;processenvrenv = "1"; # env can only be string variabler ;processenvrenv = "2";r ;processenvrenv = "3"r
R:
if (Sys.getenv("renv") == "1") cat(Sys.getenv("renv"));if (Sys.getenv("renv") == "2") { print(10); print(20); Sys.sleep(1); # necessary method, prevent pipe clogging cat(30);}if(Sys.getenv("renv") == "3") { args <- commandArgs(TRUE); cat(args); # output : passing data 100 unrecommanded}