| GetoptLong {GetoptLong} | R Documentation |
Getopt::Long in R
Wrapper of the Perl module Getopt::Long in R
GetoptLong(..., help = TRUE, version = TRUE, envir = parent.frame(), argv_str = NULL,
head = NULL, foot = NULL, script_name = NULL)
... |
specification of options. The value should be a vector having even number of elements. |
help |
whether to add help option. The help message is automatically generated according to user's specification of arguments. |
version |
whether to add version option |
envir |
user's enrivonment where |
argv_str |
command-line arguments, only for testing purpose |
head |
head of the message when invoking |
foot |
foot of the message when invoking |
script_name |
alternative script name, internal use |
Following shows a simple example. Put following code at the beginning of your script (e.g. foo.R):
library(GetoptLong)
cutoff = 0.05
GetoptLong(
"number=i", "Number of items, integer, mandatory option",
"cutoff=f", "cutoff to filter results, optional, default (0.05)",
"verbose", "print messages"
)
Then you can call the script from command line either by:
~\> Rscript foo.R --number 4 --cutoff 0.01 --verbose
~\> Rscript foo.R -n 4 -c 0.01 -v
~\> Rscript foo.R -n 4 --verbose
In above example, number is a mandatory option and should only be integer mode. cutoff
is optional and already has a default value. verbose is a logical option. If parsing is
successful, two variables with name number and verbose will be imported into the working
environment with specified values, and value for cutoff will be updated if it is specified in
command-line argument.
For advanced use of this function, please go to the vignette.
Zuguang Gu <z.gu@dkfz.de>
# There is no example NULL