首页 > 解决方案 > node不识别r exe启动路径

问题描述

我正在尝试在节点中使用 r-integration 包,

在我的环境“PATH”变量中,我有 r 的路径

C:\apps\R-3.6.2\bin\x64;

由于 IT 原因,我无法将 r 安装到程序文件中。

当我在节点中运行它时

const R = require('r-integration');

let result = R.executeRCommand("max(1,2,3)");
console.log(result);

我收到一个错误

未捕获的错误:ENOENT:没有这样的文件或目录,lstat 'C:\Program Files\R'

有没有办法让它与当前的 r 路径一起工作?

谢谢

标签: node.js

解决方案


R不幸的是,除了进入程序文件目录之外,您似乎无能为力。如果你看一下source-code,路径是硬编码的:

if (fs.lstatSync("C:\\Program Files\\R").isDirectory()){
    // Rscript is installed, let's find the path (verison problems)
    installationDir = "C:\\Program Files\\R";

您当然可以分叉存储库并更改代码以允许自定义路径甚至更好 - 创建拉取请求以使目录可配置。


推荐阅读