getopt 1.21.1
CRAN release: 2026-04-27
Breaking changes
- You can now store negative numbers like
-12even when storage mode is not “double” or “integer” (e.g. when storage mode is “character” or “complex”). If the option’s action is “store_optional” with a storage mode other than “double” or “integer” we will now store such negative numbers instead of treating them as a short flag bundle and if the option’s action is “store” we will store such negative numbers instead of throwing an error. - For long flags the storage mode column of
specnow only casts any taken argument values to the requested storage mode. In particularstore_truenow never casts to the requested storage mode andstore_optionalonly casts to the requested storage mode when the optional argument value is present and taken. This was the documented behaviour and the previous/current behavior for short flags.
New features
-
getopt()now has support for positional arguments (operands) (#2):-
getopt()now has anoperandargument that controls how positional arguments (operands) are handled:-
"after--only"(the default) only collects operands that appear after a"--"separator. -
"strict"(in addition to operands that appear after a"--"separator) collects tokens that do not look like flags and were not consumed as a flag argument, while still erroring on unrecognized flags.
Any positional arguments are returned in the
"operand"attribute of the output. -
New
getoperand()function to extract the positional arguments (operands) stored in the"operand"attribute of output ofgetopt().
-
-
getopt()andgetusage()now support action strings in column 3 ofspec(#11):-
"append"appends each argument to a vector each time the flag is used. -
"count"stores integer count of each time the flag is used. -
"store"stores argument value, legacy1supported as an alias. -
"store_false"storesFALSE. -
"store_optional"stores argument value if present otherwise storesTRUE, legacy2supported as an alias. -
"store_true"storesTRUE, legacy0supported as an alias.
-
New
getfile()function returns name of calling script, it is an alias of pre-existingget_Rscript_filename().New
getusage()function generates a usage string from a getoptspecmatrix.
Bug fixes and minor improvements
-
getfile()now also checks theLITTLER_SCRIPT_PATHenvironment variable so it works when called fromlittler(#16). - The
specargument ofgetopt()andgetusage()may now also be a 4-5 column data frame (which will be silently coerced to a matrix). - The list returned by
getopt()is now of S3 class"getopt"and no longer contains ancharacter(0L)ARGSelement.
getopt 1.20.4
CRAN release: 2023-10-01
- Documentation tweaks eliminating a CRAN check NOTE.
-
covr is no longer a “suggested” package in the
DESCRIPTIONfile.
getopt 1.20.3
CRAN release: 2019-03-22
- Now by default
getopt()won’t override a user specifiedoptargument ifargvis in the global environment. Will continue to useargvas a default foroptif it is in the global environment and the user does not specify anoptargument (forlittlercompatibility).
getopt 1.20.2
CRAN release: 2018-02-16
- Now allows one to pass an empty string to a character option. Thanks Matthew Flickinger for bug report.
getopt 1.20.1
CRAN release: 2017-11-29
- Now explicitly imports the
na.omit()method from thestatspackage. Thanks Derrick Oswald for bug report. - Improved parsing for negative numbers preceded by a space instead of a ‘=’ sign. Thanks Roman Zenka for improved regular expression.
- Slightly more informative error message if
storage.mode()coercion results in anNA. Thanks Roman Zenka for suggestion.
getopt 1.20.0
CRAN release: 2013-08-30
- Type of “numeric” in spec automatically cast to “double”. Previously users might have had an error passing negative numbers if they accidentally specified “numeric” instead of “double”.
- Project website moved to https://github.com/trevorld/getopt
- Exports new function
sort_list().
getopt 1.19.1
CRAN release: 2013-03-04
- If a passed in option matches multiple options in the getopt specification but matches one exactly then
getoptnow uses that value instead of throwing a “long flag is ambiguous” error.
getopt 1.19.0
CRAN release: 2012-11-18
- Exports new function
get_Rscript_filename()that returns name of calling script, getopt now uses this function value as default forcommandargument. - Documentation improved and now highlights differences between getopt and optparse packages for new undecided users.