1478963
1478963

Reputation: 1216

Rscript Subprocess Python

By google I have found that the way to call R code is to use the following:

subprocess.call("Rscript" + " /path/Rscript.R")

# The reason there is an add statment is because in actual code I have a 
variable of where the script is. 

On my home computer such code works. I am now working on a Server machine. If while in the the direcotry of my code I run

Rscript /path/Rscript.R

it works. However when I try to run it from the python code I get No such file or Directory. I have made sure Rscript was in my path (because I could Run it from command line).

Any help would be appreciated.

I have tried running from ~/path to it, ./path to it, /absolutepathtoit.

Upvotes: 1

Views: 734

Answers (1)

falsetru
falsetru

Reputation: 369044

There's a needless parenthesis at the end of the line:

subprocess.call("Rscript" + "/path/Rscript.R"))
                                              )

And, you need to insert a space between a command and arguments. Otherwise Rscript/path/Rscript.R is recognized as a command.

subprocess.call("Rscript" + " " + "/path/Rscript.R")
                            ^^^

Or pass a list:

subprocess.call(["Rscript", "/path/Rscript.R"])

Upvotes: 2

Related Questions