[R] is there a way of identifying batch mode running?

William Dunlap wdunlap at tibco.com
Thu May 3 02:36:53 CEST 2012


interactive() does not do exactly what you
ask for, but may be close enough.  It returns
FALSE when run from Rscript and TRUE from
R when you have not redirected standard input.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Paul.Rustomji at csiro.au
> Sent: Wednesday, May 02, 2012 5:10 PM
> To: r-help at r-project.org
> Subject: [R] is there a way of identifying batch mode running?
> 
> Hello list
> Is there a way of identifying from within R whether a script has been source(d) from
> Rgui.exe or via Rscript.exe in batch mode?
> 
> For the code I have I use the commandArgs() function to pick up command line args when
> running in batch mode via Rscript.exe
> 
> However I like to get the code working manually first using source("MyRCode.r")
> 
> I'd like to be able to put something at the top of the file that discriminates between the
> two running modes eg
> 
> #Rscript.exe --slave -e source('MyRCode.r') "some_data_file.txt"
> 
> if(batchmode = TRUE){
> #get arguments for script from command line
>  foo <- commandArgs() #where commandArgs() returns "some_data_file.txt"
> }
> 
> if(batchmode == FALSE){
> #no command line usage so need to manually supply starting arguments for script
>  foo <- "some_data_file.txt"
> }
> 
> 
> 
> 
> 
> 	[[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