GetoptLong: Wrapper of the Perl module 'Getopt::Long' in R

Description Usage Arguments Details Author(s) Examples

View source: R/get_options.R

Description

Wrapper of the Perl module Getopt::Long in R

Usage

1
2
3
GetoptLong(..., help_head = NULL, help_foot = NULL, envir = parent.frame(),
    argv_str = NULL, template_control = list(),
    help_style = GetoptLong.options$help_style)

Arguments

...

Specification of options. The value can be a two-column matrix, a vector with even number of elements or a text template. See the vignette for detailed explanation.

help_head

Head of the help message when invoking Rscript foo.R --help.

help_foot

Foot of the help message when invoking Rscript foo.R --help.

envir

User's enrivonment where GetoptLong looks for default values and exports variables.

argv_str

A string that contains command-line arguments. It is only for testing purpose.

template_control

A list of parameters for controlling when the specification is a template.

help_style

The style of the help messages. Value should be either "one-column" or "two-column".

Details

Following shows a simple example. Put following code at the beginning of your script (e.g. foo.R):

1
2
3
4
5
6
7
8
    library(GetoptLong)

    cutoff = 0.05
    GetoptLong(
        "number=i", "Number of items.",
        "cutoff=f", "Cutoff for filtering results.",
        "verbose",  "Print message."
    )  

Then you can call the script from command line either by:

1
2
3
4
    Rscript foo.R --number 4 --cutoff 0.01 --verbose
    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 this example, number is a mandatory option and it should only be in integer mode. cutoff is optional and it already has a default value 0.05. verbose is a logical option. If parsing is successful, two variables number and verbose will be imported into the working environment with the specified values. Value for cutoff will be updated if it is specified in command-line.

For advanced use of this function, please go to the vignette.

Author(s)

Zuguang Gu <z.gu@dkfz.de>

Examples

1
2
# There is no example
NULL

GetoptLong documentation built on Jan. 8, 2021, 2:29 a.m.