createArgument: Method for generating a single argument

Description Usage Arguments Details Note Examples

Description

This method provides an interface for creating a single argument. While it is not recommended for use in production ready code, this allows any user to illustrate the creation of individual parser components and may potentially speed up interpretation for scripts of 1 - 2 arguments by avoiding the need for an interface to the R6 class. However, it is still recommended to interact with the standard interface outside of visualizing the methodology.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
createArgument(
  sflag,
  lflag,
  name,
  narg,
  flag = FALSE,
  required = TRUE,
  parse.func,
  additional_args = list(),
  parse.func.opt = list()
)

Arguments

sflag

smallest flag

lflag

longest flag

name

name of the argument. This becomes the name of any parsed argument and is used for extracting by name. If null lflag is used instead.

narg

argument for deciding the behaviour when passed multiple arguments. See details for more information.

Details

For those familiar with the argparse package in python the narg argument works in a very similar fashion to narg in their package with a few extensions. The valid options are "?", "*", "+", "N", "N+" and "N-". The first four works exactly the same, while the latter two provides some addditional options for "at least" and "at most" N arguments.

  1. narg = "?" indicates that we accept either 0 or 1 argument.

  2. narg = "*" indicates that any number of arguments (0, 1, 2, ...) are accepted

  3. narg = "+" indicates that require at least 1 argument.

  4. narg = "N" (where N is an integer) indicates that we accept N and only N arguments

  5. narg = "N+" indicates that we accept N or more arguments but not less

  6. narg = "N-" indicates that we accepted N or less arguments.

Note that an argument with narg = "+" and required = FALSE is equivalent to specifying narg = "*". For narg = "N" and narg = "N+" specifying required = FALSE will have an effect similar to "?" and "+" but starting from "N". Eg. we require either 0 arguments, "N" or "N+" arguments. As a slight note this does mean that narg = 1 is equivalent to narg = "?" as the behaviour is fully controlled by required = TRUE/FALSE.

If the argument is a flag (indicated by setting flag = TRUE) both narg and required are ignored internally.

FIX ME:: add description of remaining arguments:

Note

if nchar(sflag) > nchar(lflag) the arguments are switched internally.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Create a simple argument and extract it's values.
f <- createArgument('h', 'help', 'help', 3, TRUE, FALSE)
getflags(f)
getsflag(f)
getlflag(f)
getnarg(f)
getnargparsed(f)
isflag(f)
isrequired(f)
getname(f)

Bijaelo/cmdline.arguments documentation built on June 12, 2021, 1:42 p.m.