argParse: Parser of command-line parameters in BIOS style

Description Usage Arguments Details Value Examples

View source: R/argparse.R

Description

Parser of command-line parameters in BIOS style

Test whether the given option is present in the command line or not

Usage

1
2
3
argParse(optargs, reqargs, usage = paste(scriptName(), "-h"), strict = TRUE)

argPresent(opt)

Arguments

optargs

String describing optional arguments. Syntax: <optname1>[,paramcnt1] <optname2>[,paramcnt2].... Example: “verbose outfile,1” means the command line has the syntax prog [-verbose] [outfile name]. It can be an empty string to express “no options”. The value for paramcnt is 0.

reqargs

String describining required arguments. Syntax: <argname1> <argname2>.... Example: “infile outfile” means the command line has the syntax prog [-infile ]infile [-outfile ]coutfile. Even if it is empty, it is checked that at least one non-optional value is given.

usage

A character string to be printed if the command-line option parsing fails

strict

Logical, are extra un-prefixed parameters allowed? If set to TRUE, the un-prefixed parameters (which must be at the end of the command line) will be returned as a character vector.

opt

Character string, option name

Details

argParse must be called before argGet,argGetPos , argPresent, or argGetDefault. It checks whether the command line syntax agrees with the specification of optargs and reqargs. If not, the usage message is printed and the program exists.

argPresent returns a boolean value indicating whether the option is present or not.

If the syntax was found correct, argGetPos can be called to fetch the indth value of the option opt (indexing from 1). For instance, if the following option -ranges 3 5 is defined, argGetPos(“range”, 2) returns 5. argGet is a shortcut to fetch the first element. If the opt is missing, the default value will be returned.

Value

argParse is used for the side effects. If strict is set to TRUE, an invisible NULL is returned; otherwise, extra un-prefixed parameters are returned as an invisible character vector

argGet and argGetPos returns a character string. argPresent returns a boolean value.

In case of any error (wrong syntax, or not-existing option) the R session quits while printing the error message.

Examples

1
2
3
4
5
6
7
## Not run: 
argParse("verbose threshold,2", "infile outfile",
         usage="prog [-infile ]infile [-outfile ]outfile [-verbose] [-threshold MIN MAX]")
argIsInit()
argPresent("verbose")

## End(Not run)

bedapub/ribiosArg documentation built on Nov. 4, 2021, 1:12 p.m.