通过google,我发现调用R代码的方法是使用以下方法:
subprocess.call("Rscript" + " /path/Rscript.R")
# The reason there is an add statment is because in actual code I have a
variable of where the script is. 在我家里的电脑上,这样的代码是有效的。我现在在服务器机器上工作。如果在代码的direcotry中,我运行
Rscript /path/Rscript.R它起作用了。然而,当我试图从python代码中运行它时,我没有得到这样的文件或目录。我已经确保Rscript在我的路径中(因为我可以从命令行运行它)。
任何帮助都将不胜感激。
我试过从~/path跑到它,./path到它,/absolutepathtoit。
发布于 2014-03-16 00:54:06
在行尾有一个不必要的括号:
subprocess.call("Rscript" + "/path/Rscript.R"))
)而且,您需要在命令和参数之间插入一个空格。否则,Rscript/path/Rscript.R将被识别为命令。
subprocess.call("Rscript" + " " + "/path/Rscript.R")
^^^或传递一份清单:
subprocess.call(["Rscript", "/path/Rscript.R"])https://stackoverflow.com/questions/22431642
复制相似问题