Skip to contents

Parse command line argument flags

Usage

parseArgs(
  required = character(),
  optional = character(),
  flags = character(),
  positional = FALSE
)

positionalArgs()

hasPositionalArgs()

Arguments

required, optional

character. Valid key-value pair argument names. For example, aaa for --aaa=AAA or --aaa AAA. Note that --aaa AAA-style arguments (note lack of =) are not currently supported.

flags

character. Valid long flag names. For example, aaa for --aaa. Short flags, such as -r, are intentionally not supported.

positional

logical(1). Require positional arguments to be defined.

Value

list. Named list containing arguments, organized by type:

  • required

  • optional

  • flags

  • positional

Note

Updated 2023-10-27.

See also

  • argparse Python package.

  • argparser R package.

  • optparse R package.

Examples

## Inside Rscript:
## > args <- parseArgs(
## >     required = c("aaa", "bbb"),
## >     optional = c("ccc", "ddd"),
## >     flags = "force",
## >     positional = TRUE
## > )
## > aaa <- args[["required"]][["aaa"]]
## > force <- "force" %in% args[["flags"]]
## > posArgs <- args[["positional"]]