Skip to content
R package providing basic command line optional argument parsing
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
exec style: Strip remaining ';'s from Allen's original R code Nov 30, 2018
man chore: Re-run 'document()' to fix Rd file Dec 15, 2018
tests test: Get unit test coverage up even higher Dec 15, 2018
.appveyor.yml chore: Get ready for 1.20.3 CRAN release Mar 22, 2019
.gitignore chore: Add cran-comments.rst [skip ci] Mar 22, 2019
.travis.yml test: Get unit test coverage up even higher Dec 15, 2018
COPYING Add COPING file Aug 30, 2013
DESCRIPTION chore: Get ready for 1.20.3 CRAN release Mar 22, 2019
NAMESPACE Tweak to documentaion and error mesages (closes #9) Nov 22, 2017



CRAN Status Badge Build Status AppVeyor Build Status Coverage Status RStudio CRAN mirror downloads Project Status: Active – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.

getopt is an R package designed to be used with Rscript to write "#!"-shebang scripts that accept short and long flags/options. Many users will prefer using instead the package optparse which adds extra features (automatically generated help option and usage, support for default values, basic positional argument support).

To install the last version released on CRAN use the following command:


To install the development version use the following command:



An example Rscript using getopt:

# get options, using the spec as defined by the enclosed list.
# we read the options from the default: commandArgs(TRUE).
spec = matrix(c(
  'verbose', 'v', 2, "integer",
  'help'   , 'h', 0, "logical",
  'count'  , 'c', 1, "integer",
  'mean'   , 'm', 1, "double",
  'sd'     , 's', 1, "double"
), byrow=TRUE, ncol=4)
opt = getopt(spec)

# if help was asked for print a friendly message
# and exit with a non-zero error code
if ( !is.null(opt$help) ) {
  cat(getopt(spec, usage=TRUE))

# set some reasonable defaults for the options that are needed,
# but were not specified.
if ( is.null(opt$mean    ) ) { opt$mean    = 0     }
if ( is.null(opt$sd      ) ) { opt$sd      = 1     }
if ( is.null(opt$count   ) ) { opt$count   = 10    }
if ( is.null(opt$verbose ) ) { opt$verbose = FALSE }

# print some progress messages to stderr, if requested.
if ( opt$verbose ) { write("writing...",stderr()) }

# do some operation based on user input.

# signal success and exit.
# q(status=0)
You can’t perform that action at this time.