当我在 R 中执行脚本时,它是:
$ R --vanilla --args test_matrix.csv < hierarchical_clustering.R > out.txt
在Python中,如果我使用:
process = subprocess.call("R --vanilla --args "+output_filename+"_DM_Instances_R.csv < /home/kevin/AV-labels/Results/R/hierarchical_clustering.R > "+output_filename+"_out.txt", shell=True)
但这个方法并没有提供process.wait()
功能。
所以,我想使用subprocess.Popen
, 我试过:
process = subprocess.Popen(['R', '--vanilla', '--args', "\'"+output_filename+"_DM_Instances_R.csv\'", '<', '/home/kevin/AV-labels/Results/R/hierarchical_clustering.R'])
但它不起作用,Python只是打开了R但没有执行我的脚本。
为其提供 Rscript 的路径,而不是“R”。我有同样的问题。打开 R 但不执行我的脚本。您需要调用 Rscript(而不是 R)来实际执行脚本。
retcode = subprocess.call("/Pathto/Rscript --vanilla /Pathto/test.R", shell=True)
这对我有用。
Cheers!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)