OptionParserOption-class: Class to hold information about command-line options

OptionParserOption-classR Documentation

Class to hold information about command-line options

Description

Class to hold information about command-line options

Slots

short_flag

String of the desired short flag comprised of the - followed by a single non-dash character (but not = or a whitespace character).

long_flag

String of the desired long flag comprised of ⁠--⁠ followed by a non-dash character and then (optionally) more characters (but not any = or whitespace characters).

action

A character string describing the action optparse should take when it encounters an option. One of:

  • "append": appends each occurrence's value to default (or to an empty vector if default is NULL). Returns NULL if never seen and default is NULL.

  • "callback": stores the return value of the callback function.

  • "count": counts the number of times the flag is seen and adds it to default (treated as 0L if not supplied). Returns NULL if never seen and no default was supplied.

  • "store" (default): stores the specified following value.

  • "store_const": stores const if the flag is seen, otherwise default. Returns NULL if the flag is not seen and default is NULL.

  • "store_true": stores TRUE if the option is found.

  • "store_false": stores FALSE if the option is found.

If callback is not NULL the default action is "callback" otherwise it is "store".

type

A character string specifying which data type to store: "logical", "integer", "double", "complex", or "character" ("numeric" is an alias for "double"). Defaults:

  • if action == "count" then "integer"

  • if action %in% c("store_false", "store_true") then "logical"

  • if action == "store" and default is not NULL then typeof(default)else if default is NULL then "character"

dest

A character string specifying what field in the list returned by parse_args() should optparse store the option value. Default is derived from the long flag in opt_str.

default

The default value optparse should use if it does not find the option on the command line.

const

The value to store when action = "store_const" and the flag is seen. Ignored for all other actions.

required

If TRUE, parse_args() will throw an error if this option is not provided on the command line. Note: Required options are generally considered bad form because users expect options to be optional, and thus they should be avoided when possible.

help

A character string describing the option, used by print_help() in generating a usage message. "%default" will be substituted by the value of default.

metavar

A character string that stands in for the option argument when printing help text. Default is the value of dest.

callback

A function that executes after the option value is fully parsed. Its return value is assigned to the option. Arguments are: the option S4 object, the long flag string, the value of the option, the parser S4 object, and ....

callback_args

A list of additional arguments passed to callback (via do.call()).

See Also

make_option()


optparse documentation built on April 17, 2026, 9:06 a.m.