Utilities

Utilities

Rscript Option parser

# Add option parser library
suppressPackageStartupMessages(library(optparse))

# Add options to script; 
option_list <- list(
	# opt$export is set to true in case parameter is provided (store_true), otherwise false
	make_option(c("--export"), action = "store_true", type = "logical", 
        default = FALSE, help = "Export data"),
    make_option(c("--myParameter"), action = "store", type = "character", 
        default = NULL, help = "Description of input parameter"))

# Method call
opt <- parse_args(OptionParser(option_list = option_list))

# make option mandatory
if (is.null(opt$myParameter)){
stop ('Mandatory argument not provided. Please specify target file')
}

myParameter = opt$myParameter