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]]
'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 file. 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() Regards, Simon 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. >
This is a python not an R problem. Use of redirection is handled by a shell, not by the executable (usually: it could depend on the compiler). The Windows system and popen commands (and hence R's system()) does not use a shell: POSIX OSes do. It will be cleaner to use Rscript to run scripts. Please ask Python questions on a Python help list. On Sat, 18 Oct 2008, Tomislav Pu?a 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.You'll need to explain the arbtirary restrictions you are imposing here.> 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595