[R] R script from Python

Simon Knapp sleepingwell at gmail.com
Sat Oct 18 06:19:33 CEST 2008

'Rterm --help' shows the usage as:

Rterm [options] [< infile] [>outfile] [EnvVars]

just in case you didn't understand what the angle brackets meant:

the term "[< infile]" means "read input from 'infile'", and
the term "[> outfile]" means "write output to 'outfile'".

Though your code works at the command line, the spacing appeared to
imply that you thought the angle brackets simply 'wrapped' the input

This syntax doesn't work from python as the angle brackets are OS
shell operators but won't be interpreted that way when used to
construct a Popen object.

the following will do what you want:

import subprocess
command  = 'c:\\Program Files\\R\\R-2.7.2\\bin\\Rterm.exe --vanilla -q
-f d:\\test\\run\\geneBank.r'
subprocess.Popen(command, stdout=open('d:\\output.out', 'w')).wait()


On Sat, Oct 18, 2008 at 10:28 AM, Tomislav Puđa <xxk363 at gmail.com> wrote:
> Hi,
> I'm trying to execute R-script from Python. I'm using R 2.7.2, Python 2.5
> and WinXP.
> I don't won't to use Python/R interface because of nature of project.
> Python code :
> import subprocess
> command  = 'c:\\Program Files\\R\\R-2.7.2\\bin\\Rterm.exe --vanilla -q
> <d:\\test\\run\\geneBank.r> d:\\output.out'
> subprocess.Popen(command).wait()
> After that, I get error messages on Rterm.exe terminal :
> ARGUMENT 'd<:\lloydMax.r>' __ignored__
> ARGUMENT 'd:\output.txt' __ignored__
> Why ?
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list