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. 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
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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no
Hi! You can do it indirectly e.g within a batch file. a) set an envirovment variable (the path to the file) b) access it from within you *.R script using ?Sys.getenv Hope it helps. Eryk *********** REPLY SEPARATOR *********** On 8/27/2004 at 4:36 PM 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. >>> >>>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 >>> >>>______________________________________________ >>>R-help at stat.math.ethz.ch mailing list >>>https://stat.ethz.ch/mailman/listinfo/r-help >>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlDipl. bio-chem. Eryk Witold Wolski @ MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin 'v' tel: 0049-30-83875219 / \ mail: wolski at molgen.mpg.de ---W-W---- http://www.molgen.mpg.de/~wolski
Hi, 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, Kishore -----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 quote.R: commandArgs()[-(1:3)] q() and a batch file quote.bat: Rterm.exe --slave --args %* < quote.R Then [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 documentation. 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