optparse 1.8.2
CRAN release: 2026-04-17
New features
-
add_option()(andmake_option()) now support the following new actions (#22):-
action = "append"which appends each occurrence’s value todefault. -
action = "append_const"which appendsconsttodefaulteach time the flag is seen. -
action = "count", which counts the number of times a flag is seen and adds it todefault(treated as0Lif not supplied). ReturnsNULLif the flag is never seen and nodefaultwas supplied. -
action = "store_const"which storesconstwhen the flag is seen.
-
add_option()(andmake_option()) now support aconstparameter (intended for new actions"append_const"and"store_const").-
Several new classed errors are now thrown, mirroring Python’s
optparseexception hierarchy:-
optparse_option_error: invalid option definition inmake_option()oradd_option().-
optparse_option_conflict_error: duplicate flag inOptionParser()oradd_option().
-
-
optparse_parse_error: existing base class for all parse-time errors fromparse_args().-
optparse_bad_option_error: unrecognized, misused, or argument-requiring option.-
optparse_ambiguous_option_error: ambiguous abbreviated long flag.
-
-
optparse_bad_positional_arguments_error: wrong number of positional arguments supplied. -
optparse_missing_required_error: a required option was not supplied.
-
-
add_option()(andmake_option()) now allow non-letter characters in short flags (e.g.,-1) and at the beginning of long flags (e.g.,--1flag), following Python’soptparseconvention. However long and short flags may not contain=or whitespace (or begin with hyphens).add_option()(andmake_option()) now support arequiredargument. IfTRUE,parse_args()will throw an error if the option is not provided on the command line (#17).
Bug fixes and minor improvements
-
parse_args()(andparse_args2()) now correctly handle a bare--separator: all arguments after--are treated as positional arguments rather than options. -
parse_args()(andparse_args2()) now support abbreviated long flags (e.g.--verbmatching--verbose) whenpositional_argumentsis notFALSE. Previously abbreviations were only supported whenpositional_arguments = FALSE. -
make_option()now throws a classedoptparse_option_errorfor invalidactionortypearguments instead of a confusing error later at parse time. -
OptionParser()now also checks theLITTLER_SCRIPT_PATHenvironment variable for the script name when performing%progon theusageargument so it works when called fromlittler.
optparse 1.7.4
CRAN release: 2024-01-16
- Revises vignette engine specification in the
DESCRIPTIONto suppress new CRAN check NOTE (#43).
optparse 1.7.3
CRAN release: 2022-07-20
-
The errors raised by
parse_args()(andparse_args2()) are now of class “optparse_parse_error”.When
interactive()isFALSEwe now print out a usage string followed by a (less verbose) error message. Throws a more informative error message for unknown short flags when
positional_arguments=TRUE. Thanks Greg Minshall for bug report (#42).
optparse 1.7.1
CRAN release: 2021-10-08
- Add a
formatterargument toOptionParser()for a function to format the usage message (#30). By default uses the new functionIndentedHelpFormatter(). optparse also provides the new functionTitledHelpFormatter(). Thanks Ni Huang for suggestion.
optparse 1.6.6
CRAN release: 2020-04-16
- Throws an error for unknown short flags and long flags when
positional_arguments=TRUE. Thanks Greg Minshall for bug report (#34). - If the
callbackparameter ofadd_option/make_optionis notNULLthen the default ofactionis now"callback". Thanks Greg Minshall for suggestion (#35). - Better documentation of
action=="callback"in the man page foradd_optionandmake_option. Thanks Greg Minshall for bug report (#35).
optparse 1.6.2
CRAN release: 2019-04-02
- Fixs a parsing bug when
action=="callback"andpositional_argument==TRUE(#28). Thanks Ni Huang for bug report.
optparse 1.6.1
CRAN release: 2019-01-15
- Improves accuracy of README (#27). Thanks Alex Penson for bug report.
optparse 1.6.0
CRAN release: 2018-06-17
- Supports callback actions (#26). Thanks Gyu Jin Choi for patch.
- If
interactive() == FALSEandprint_help_and_exit == TRUEthenoptparsewill now callquit(status=0)instead ofquit(status=1)after printing the help message (this matches behaviour of the python package). - Better error message when forgetting to set
add_help_option=FALSEwhen defining an-hor--helpflag. Thanks Jeff P. Bruce for bug report. - Increment
getoptrequirement so that empty strings are parsed correctly. Thanks Matthew Flickinger for bug report.
optparse 1.4.4
CRAN release: 2017-07-18
- Minor documentation fixes. Thanks J. J. Ramsey and Daeyoung Kim for bug reports.
- Fix bug when
add_help_optioninOptionParserset toFALSE. Thanks to Jeff Bruce for bug report. -
parse_argsnow supportsconvert_hyphens_to_underscoresargument which converts any hyphens to underscores when returning the list of options - Now includes the convenience function
parse_args2which wrapsparse_argswithpositional_argumentsset toTRUEandconvert_hyphens_to_underscoresset toTRUE.
optparse 1.3.2
CRAN release: 2015-10-03
-
optparseshould no longer give any warnings whenoptions(warnPartialMatchArgs=TRUE). Thanks Rich FitzJohn for patch. -
print_helpno longer throws an error if we have a default argument of length zero. Thanks Benjamin Tyner for bug report.
optparse 1.3.0
CRAN release: 2014-12-11
-
OptionParserandOptionParserOptionS4 classes are now exported. Thanks Peter Humburg for patch.
optparse 1.2.0
CRAN release: 2014-04-04
- Parameter
positional_argumentsof functionparse_argsnow accepts one or two numeric values that denote the minimum and maximum number of supported positional arguments. Thanks Kirill Müller for patch. - If
interactive() == TRUEthenparse_argswill no longerquit(status=1)after printing a help message but will instead throw an error.optparsewill continue toquit(status=1)after printing a help message for non-interactive Rscripts unlessprint_help_and_exit == FALSE. - In
make_optionargumenttype="numeric"automatically cast todouble. Previously users might have received an error passing negative numbers if they accidentally specified “numeric” instead of “double”. - Bug fixed in printing usage message for options with default value of NA and a help string including “%default”. Thanks Stefan Seemayer for bug report and patch.
optparse 1.0.2
CRAN release: 2013-08-26
- Project website moved to https://github.com/trevorld/optparse
- We now replace all occurrences of %prog in usage message (including description and epilogue). Previously we would only replace one occurrence and didn’t make replacements in description and epilogue.
- Fix bug in
parse_argswhen we have options with no short flag and positional_arguments=TRUE. Thanks Miroslav Posta for bug report.
optparse 1.0.0
CRAN release: 2012-11-21
- Added
descriptionandepiloguearguments toOptionParserto allow users to add more information to generated help messages - Slightly alters the generated usage string to match more closely what the Python module does
- No longer exports S4 classes that represent OptionParser and OptionParserOption
- Now requires package getopt (>= 1.19) which has also been moved to Imports field from Depends field in DESCRIPTION
- Now also Suggests stringr package in DESCRIPTION