Reputation: 981
I can't get optparse to work with short arguments. What's wrong with this?
library("optparse")
packageVersion("optparse")
option_list = list(
make_option(c("-f", "--file"), action = "store", type="character", default=NULL)
)
opt_parser = OptionParser(option_list=option_list)
parse_args(opt_parser, args=c("--file=anyfile.txt")) # this works
parse_args(opt_parser, args=c("-f anyfile.txt")) # but this does not
[1] ‘1.7.1’
Error in getopt_options(object, args) :
Error in getopt(spec = spec, opt = args) :
short flag "f" requires an argument, but has none
Upvotes: 1
Views: 778
Reputation: 376
args
is a character vector. From help:
A character vector containing command line options to be parsed. Default is everything after the Rscript program in the command line. If positional_arguments is not FALSE then parse_args will look for positional arguments at the end of this vector.
args=c("-f", "anyfile.txt")
Upvotes: 0