WAF
WAF

Reputation: 1151

Execute R script with python subprocess.call

I want to execute a R script from a python script using:

subprocess.call("Rscript script.R --args arg1 arg2", shell=True)

How do I have to write my script.R in order to use the args?

Upvotes: 2

Views: 1646

Answers (1)

flodel
flodel

Reputation: 89057

Using commandArgs like this:

args <- commandArgs(trailingOnly = TRUE)

arg1 <- args[1]
arg2 <- args[2]
[...your code...]

Also make sure that the Rscript executable is in your PATH.

Upvotes: 0

Related Questions