【问题标题】:Catch execute result from R script从 R 脚本捕获执行结果
【发布时间】:2021-05-18 15:59:16
【问题描述】:

我有一个从 Python 调用的 R 脚本,我想从中捕获输出。我可以写入 CMD 和 TXT,但我想在 Python 脚本中捕获输出,以便使用它。

在我尝试过的python脚本中:

logging.debug (os.popen ('Rscript testScript.r'))

但它不起作用。我也试过:

output = cmd ('Rscript testScript.r')

print (output)

但它返回 None 作为输出。

在 R 中我尝试过:returnValue (TRUE),但它写入 CMD,输出仍然是 None

如何让 R 脚本返回一个值,我可以过滤以查看结果???

非常感谢您。

【问题讨论】:

    标签: python r return


    【解决方案1】:

    我找到了解决办法:

    在 R 中,我们可以将选项放在 Try/catch

      error = function (cond)
    

    这反映了在 Python 中我们可以收集的输出:

      print (stderr)
      print (stdout)
    

    其中 stderr 是输出错误,stdout 是标准输出。

    希望如果有人遇到类似问题,它会有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-10-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 2013-01-03
      相关资源
      最近更新 更多