From davison at stats.ox.ac.uk  Sat Jan  5 20:34:07 2008
From: davison at stats.ox.ac.uk (Dan Davison)
Date: Sat, 5 Jan 2008 19:34:07 +0000
Subject: [Rd] Rscript argument processing minor bug with -g
Message-ID: <20080105193407.GA13024@stats.ox.ac.uk>

I think there's a minor bug in the argument-processing carried out by Rscript.
The effect is that if one passes "-g" as a flag to the script, it is erroneously 
exposed to the main executable's argument processing and therefore generates a 
message about not being able to comply with the request for a particular GUI. 
Uppercase G is fine as are the other 25 letters in upper or lower case.

I noticed this with R-2.5.1 and carried out the tests below with R-devel-2.7.0.

Dan

platform       i686-pc-linux-gnu                                               
arch           i686                                                            
os             linux-gnu                                                       
system         i686, linux-gnu                                                 
status         Under development (unstable)                                    
major          2                                                               
minor          7.0                                                             
year           2008                                                            
month          01                                                              
day            04                                                              
svn rev        43862                                                           
language       R                                                               
version.string R version 2.7.0 Under development (unstable) (2008-01-04 r43862)

[fedora core 5]

## No problem with -a -b -f -h

~/src/scripts/R> /usr/src/R/R-devel/bin/Rscript -e "commandArgs()" -a -b -f -h
 [1] "/usr/src/R/R-devel/bin/exec/R" "--slave"                      
 [3] "--no-restore"                  "-e"                           
 [5] "commandArgs()"                 "--args"                       
 [7] "-a"                            "-b"                           
 [9] "-f"                            "-h"   

## But if -g is in there, there's a warning message

~/src/scripts/R> /usr/src/R/R-devel/bin/Rscript -e "commandArgs()" -a -b -f -g -h
WARNING: unknown gui '-h', using X11

 [1] "/usr/src/R/R-devel/bin/exec/R" "--slave"                      
 [3] "--no-restore"                  "-e"                           
 [5] "commandArgs()"                 "--args"                       
 [7] "-a"                            "-b"                           
 [9] "-f"                            "-g"                           
[11] "-h"                           

~/src/scripts/R> /usr/src/R/R-devel/bin/Rscript -e "commandArgs()" -a -b -f -g not_a_gui -h
WARNING: unknown gui 'not_a_gui', using X11

 [1] "/usr/src/R/R-devel/bin/exec/R" "--slave"                      
 [3] "--no-restore"                  "-e"                           
 [5] "commandArgs()"                 "--args"                       
 [7] "-a"                            "-b"                           
 [9] "-f"                            "-g"                           
[11] "not_a_gui"                     "-h"      

## The problem remains if the R code is in a file rather than in-line,
## and also with a #! style script:

~/src/scripts/R> cat test.R 
#!/usr/src/R/R-devel/bin/Rscript
commandArgs()

~/src/scripts/R> ./test.R -a -g invalid_gui
WARNING: unknown gui 'invalid_gui', using X11

[1] "/usr/src/R/R-devel/bin/exec/R" "--slave"                      
[3] "--no-restore"                  "--file=./test.R"              
[5] "--args"                        "-a"                           
[7] "-g"                            "invalid_gui"        

~/src/scripts/R> cat test2.R 
commandArgs()
~/src/scripts/R> /usr/src/R/R-devel/bin/Rscript test2.R -a -g
WARNING: --gui or -g without value ignored
[1] "/usr/src/R/R-devel/bin/exec/R" "--slave"                      
[3] "--no-restore"                  "--file=test2.R"               
[5] "--args"                        "-a"                           
[7] "-g"



[Rd] Rscript argument processing minor bug with -g
Dan Davison