Executing an R script in python via subprocess.Popen

前端 未结 5 541
逝去的感伤
逝去的感伤 2021-01-20 23:25

When I execute the script in R, it is:

$ R --vanilla --args test_matrix.csv < hierarchical_clustering.R > out.txt

In Python, it works if

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 00:22

    Instead of 'R', give it the path to Rscript. I had the same problem. Opens up R but doesn't execute my script. You need to call Rscript (instead of R) to actually execute the script.

    retcode = subprocess.call("/Pathto/Rscript --vanilla /Pathto/test.R", shell=True)
    

    This works for me.

    Cheers!

提交回复
热议问题