From edd at debian.org  Tue Jan 15 05:16:06 2008
From: edd at debian.org (Dirk Eddelbuettel)
Date: Mon, 14 Jan 2008 22:16:06 -0600
Subject: [Rd] Rscript argument processing minor bug with -g
In-Reply-To: <20080105193407.GA13024@stats.ox.ac.uk>
References: <20080105193407.GA13024@stats.ox.ac.uk>
Message-ID: <18316.13190.684215.761581@ron.nulle.part>


On 5 January 2008 at 19:34, Dan Davison wrote:
| 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.
[...]
| ~/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"                           

For what it's worth, littler does not have that problem with   Following GNU
traditions, we stick all arguments that are not referring to existing
switches into the argv vector which you can access normally:

	edd at ron:~> r -e 'print(argv)' -- -a -b -f -g -h -i -j
	[1] "-a" "-b" "-f" "-g" "-h" "-i" "-j"

It is then up to you to parse these remaining arguments. If you hit an
existing option like -h _before_ the --, its code gets invoked.  This also
works when code is piped into littler (when '-' is used to turn on stdin
parsing):

	edd at ron:~> echo 'print(argv)' | r - -- -a -b -f -g -h -i -j
	[1] "-a" "-b" "-f" "-g" "-h" "-i" "-j"

Prior versions had an off-by-one error in the way argv was built, but version
0.1.0 which I just put onto

	http://dirk.eddelbuettel.com/code/littler.html

should be fine.

Hope this helps,  Dirk

-- 
Three out of two people have difficulties with fractions.



[Rd] Rscript argument processing minor bug with -g
Dirk Eddelbuettel