Running Rscript via Python using os.system() or subprocess()

后端 未结 2 1215
长情又很酷
长情又很酷 2021-01-28 18:24

I am facing problems running a Rscript via Python using os.system() or subprocess().

Using os.system() to run commands via python works generally fine for me (e.g. with

2条回答
  •  情歌与酒
    2021-01-28 18:53

    It probably is way too late now and I have seen you solved the issue, but I was having a similar issue (although in a Linux system) and it might help someone else now; this command was not working when called inside python although it worked directly on the terminal/command-line.

    os.system("R CMD BATCH ./read_lengths_batch.R")
    

    I tried many solutions, including subprocess and others but found it to be easier than that. In my case, and I understand it might be different in Windows, I just had to add a & at the end of the call for it to run in the background. Somehow it seemed R would shut down with the Python script instead of doing its work.

    os.system("R CMD BATCH ./read_lengths_batch.R &")
    

    Strangely, it was also working if in my folder I would have the same file copied with a .txt extension: read_lengths_batch.R and read_lengths_batch.txt.

    Hope it helps someone!

提交回复
热议问题