我在本地保存了一个.R文件,路径如下:
Rfilepath = "C:\\python\\buyback_parse_guide.r"
命令RScript.exe是:
^{pr2}$我试着跑步:
subprocess.call([RScriptCmd,Rfilepath],shell=True)
但是它返回1,.R脚本没有成功运行。我做错什么了?我是Python新手,所以这可能是一个简单的语法错误。。。我也试过这些,但都返回1:
subprocess.call('"C:\Program Files\R\R-2.15.2\bin\Rscript.exe"',shell=True)
subprocess.call('"C:\\Program Files\\R\\R-2.15.2\\bin\\Rscript.exe"',shell=True)
subprocess.call('C:\Program Files\R\R-2.15.2\bin\Rscript.exe',shell=True)
subprocess.call('C:\\Program Files\\R\\R-2.15.2\\bin\\Rscript.exe',shell=True)
谢谢!在
看来你和我也有类似的问题。我不得不将RScript重新安装到一个没有空格的路径上。在
参见:Running Rscript via Python using os.system() or subprocess()
我是这样计算Python和Rscript之间的通信的:
Python部分:
outValue
包含执行脚本后的输出值。RR脚本中的一部分:
^{pr2}$output
是要发送给Python的变量RScriptCmd需要只是可执行文件,没有命令行参数。所以:
那么Rfilepath实际上可以是所有参数-并重命名为:
^{pr2}$相关问题 更多 >
编程相关推荐