将R与NodeJS集成

问题描述

我是Node的新手,我正在寻找一种将Node js与R编译器集成的方法。如何在Node中运行R脚本或使用R进行编译,然后得到结果?谢谢

我需要这样的东西

...

// i need to compile and get the result of a R file like this
// the R script returns a number between 0 and 100
var exp = compileRFile(" **file location** ");

if (exp <= 0.1){
    console.log(`your exp ${exp} is lower than 0.1`);
}else {

...

解决方法

我建议使用“ r-integration”软件包。该库允许您使用系统调用从Node JS环境中执行任意R命令或脚本(文件)。

要在您的Node JS项目中安装它,只需运行 npm install r-integration

您可以在此处找到有关它的更多信息: r-integration