【问题标题】:R integration with node script using r-scriptR 使用 r-script 与节点脚本集成
【发布时间】:2018-04-30 02:37:37
【问题描述】:

我有两个非常简单的文件来测试我的集成设置。首先是test.R里面的r脚本:

print('hello')

然后调用那个文件的 index.js:

var R = require("r-script");
var out = R("./test.R")
           .data()
           .callSync();

这就是我的控制台告诉我的:

$ node index.js
/home/user/index.js:3
  .data()
  ^

TypeError: Cannot read property 'data' of undefined

目前,我正在运行 Ubuntu 18.04,如果我只运行 Rscript test.R,它可以正常工作。有什么帮助吗?

【问题讨论】:

  • 你可能需要传递一些东西给.data,比如.data(0)
  • 你能解决问题吗?我在运行包中给出的示例时遇到了同样的问题,同步和异步版本都给出了相同的错误。

标签: r node.js ubuntu integration


【解决方案1】:

我用https://github.com/joshkatz/r-script/issues/19 解决了我的类似问题

如果还是懒得拉git,可以直接更新源码./node_modules/r-script/index.js,然后编辑函数init 作为

function init(path) {
  var obj = new R(path);
  _.bindAll(obj, "data", "call", "callSync");
  return obj;
}

希望对您有所帮助。

【讨论】:

    【解决方案2】:
     $ cd node_modules/r-script
     $ rm node_modules
     $ npm install underscore@1.8.3
    

    就我而言,降级下划线有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      • 2013-08-06
      • 2012-05-14
      • 2014-11-04
      • 1970-01-01
      • 2018-02-08
      • 2020-04-13
      相关资源
      最近更新 更多