R - parse command line with both flags and arguments

02 Dec 2017

Parse both flags and additional arguments from command line:

# ex: a command line Rscript myscript.R -f myfile1 -F myfile2 fold1 fold2 fold3

opt_parser <- OptionParser(option_list=option_list);
cmdline <- parse_args(opt_parser, positional_arguments = TRUE);

# store the flags in a variable
opt <- cmdline$options
file1 <- opt$file1 # for the -f flag
file2 <- opt$file2 # for the -F flag

# store all arguments without flags
all_folders <- cmdline$args   # will store c(fold1, fold2, fold3)
[ R  command line  ]