【问题标题】:How to run a R script through Python by passing command line arguments如何通过传递命令行参数通过 Python 运行 R 脚本
【发布时间】:2014-07-31 02:08:48
【问题描述】:

我正在尝试通过传递命令行参数通过 Python 运行 R 脚本。我正在使用这段代码:

proc=subprocess.Popen(["Rscript", "modelcriteria.R", "--args","model_selection_criteria.csv"])

我遇到了这个错误:

Error in file(file, "rt") : cannot open the connection
...
In file(file, "rt") : cannot open file '--args': No such file or directory
Execution halted.

我要做的就是将model_selection_criteria.csv 文件传递​​给我在Python 环境中的R 脚本。任何人都可以在我的代码中指出问题或提出替代解决方案。 提前致谢。

【问题讨论】:

  • 错误本身告诉你真相。尝试删除"--args"
  • 是的,谢谢,我已经试过了,现在运行:)

标签: python r command-line subprocess


【解决方案1】:

当您从命令行运行 modelcriteria.R 时,您使用什么命令?我对 R 不熟悉,但从错误和popen docs 来看,我认为您不需要'--args'

proc=subprocess.Popen(["Rscript", "modelcriteria.R","model_selection_criteria.csv"])

应该相当于命令行中的Rscript modelcriteria.R model_selection_criteria.csv

【讨论】:

  • 是的,我对这些类型的操作也不熟悉。你的回答有帮助。
猜你喜欢
  • 2012-06-19
  • 2017-04-20
  • 2021-10-31
  • 2017-09-13
  • 1970-01-01
  • 2014-05-11
  • 2014-10-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多