parseArgs: Parse command line argument flags

View source: R/parseArgs.R

parseArgsR Documentation

Parse command line argument flags

Description

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"]]

acidgenomics/r-koopa documentation built on Oct. 31, 2023, 9:21 a.m.