[R] About passing parameter to '.R' script file

Kishore, Tapake tapake.kishore at hp.com
Fri Aug 27 14:11:49 CEST 2004


Thanks a lot for an instant reply.
Actualy i am invoking the 'R' application from JAVA programme. I am using 'test.R' script file.

Is the below command a right one or is there any other command option available.

c:\\R\\rw1091\\bin\\R.exe CMD BATCH c:\\R\\rw1091\\bin\\test.R

I need to create a batch file for setting the environment variable and call it using commandArgs() or ?Sys.getenv.

Thanks & Regards,

-----Original Message-----
From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
Sent: Friday, August 27, 2004 5:25 PM
To: Roger Bivand
Cc: Kishore, Tapake; r-help at r-project.org
Subject: Re: [R] About passing parameter to '.R' script file

There is another solution that the helpers might like to be aware of.
Anything on the command line after --args is ignored but can be retrieved 
by commandArgs.  So suppose I have a script


and a batch file quote.bat:
Rterm.exe --slave --args %* < quote.R


[c:/R]% quote.bat foo bar bah
[1] "foo" "bar" "bah"

If people would cooperate (an identical message was sent to R-bugs this
morning, PR#7201), we might feel inclined to add such things to the

On Fri, 27 Aug 2004, Roger Bivand wrote:

> On Fri, 27 Aug 2004, Kishore, Tapake wrote:
> > Hi,
> > 
> > I am trying the 'R' application for generating the data for the uploaded
> > '.gpr' file. I have written script file named 'test.R'. Currently i have
> > hardcoded the path of uploaded '.gpr' file in the script itself.
> > 
> Typically, you can write a batch file that sets environment variables, and
> then calls R with your script file, accessing the environment variables
> from your R script using Sys.getenv(). This means that the values are not
> hard-coded in your script - just the environment variable names - and that
> the values inserted into the environment variables in your batch file are
> accessible within the script as values using the function mentioned.
> > I would like to know how to pass a command line parameter to the
> > 'test.R' script file, so that i dont have to hardcode the path and
> > filename of the '.gpr' files. Also, need to access these parameters
> > inside the script file to use the path of the uploaded file. I am using
> > below command to invoke the 'R' application by using the 'test.R' script
> > file.
> > 
> > e.g.
> > c:\\R\\rw1091\\bin\\R.exe CMD BATCH c:\\R\\rw1091\\bin\\test.R
> > 
> > Expecting your suggestion on this.
> > 
> > Thanks in advance.
> > 
> > Regards,
> > Kishore

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

More information about the R-help mailing list