Matt Anthony
2006-Nov-27 19:04 UTC
[R] calling R from cmd line, loading in data sets on the call
Hi - I have read the archives on R cmd and passing parameters, and I guess I am not totally clear if that solved this problem ... I would like to call an R script from the command line, and in the process pass in data sets and parameters ... right now, I manually specify the files to be read in as the data sets for the script, and then it processes, but I need to be able to automate this action from the cmd line. Rcmd myprogram.R is clearly documented as unable to take parameters passed to it ... I am on Windows, R 2.3.1 Thanks Matt [[alternative HTML version deleted]]
Barry Rowlingson
2006-Nov-28 09:59 UTC
[R] calling R from cmd line, loading in data sets on the call
Matt Anthony wrote:> Rcmd myprogram.R is clearly documented as unable to take parameters > passed to it ... >It can take parameters from the environment though... H:\> set METHOD=loglik H:\> "c:\Program Files\R\R-2.2.1\bin\R" blah blah > Sys.getenv("METHOD") METHOD "loglik" > Barry
John McNeil
2006-Nov-28 17:02 UTC
[R] calling R from cmd line, loading in data sets on the call
I know an answer for Unix that can perhaps you can translate to DOS. If you pass a file of R statements to 'R' on the command line it will run them. In Unix, the '|' (pipe) symbol sends text to a program as though it came from a file, thus: echo "x<-2; 2*x" | R --vanilla --slave yields [1] 4 Or you could put "x<-2; 2*x" in a file called test.R and run: R --vanilla --slave < test.R I use this to interpret user commands from labsynch wiki pages on the server ( I learned this from Alfredo Pontillo's R-php). You can run any R command, including loading other files and libraries. I use it to pass files and set the working directory. John