我想从Python运行R脚本。下面的脚本在没有“+args”时工作。有人知道传递参数有什么问题吗?你知道吗
Python脚本:
import subprocess
Iterations = 10
command = 'C:/Program Files/R/R-3.4.3/bin/Rscript.exe'
path2script = 'C:/Users/a0266997/Documents/PossionDistribution.R'
args = [str(Iterations)]
cmd = [command, path2script] + args
subprocess.Popen(cmd)
R脚本:
myArgs <- commandArgs(trailingOnly = TRUE)
Iterations = myArgs[0]
Iterations
do something in R ....
这是你的代码与一些更正,应该为你工作。我还将R代码更改为可复制的代码(例如,打印到stdout和stderr)。你知道吗
我将
subprocess.Popen(cmd)
调用更改为subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
,这将修复部分问题。R代码中也有一个补丁。你知道吗R脚本(代码的修改版本)
这已
myArgs[0]
更改为myArgs[1]
我在Mac操作系统上运行了这个,它对我有用。它至少应该让你朝着正确的方向开始,这取决于你需要的细节。你知道吗
相关问题 更多 >
编程相关推荐