library(optparse) # ------------------------------------------------------------------------------ # defaults # ------------------------------------------------------------------------------ default.ncores <- 32 default.verbose <- FALSE default.vegtype <- "all" # ------------------------------------------------------------------------------ # parsing arguments # ------------------------------------------------------------------------------ options <- list ( make_option( opt_str = c("-c", "--cores"), dest = "ncores", type = "integer", default = default.ncores, help = paste0("number of CPU cores to use, defaults to ", default.ncores), metavar = "4" ), make_option( opt_str = c("-v", "--verbose"), action = "store_true", default = default.verbose, help = "print more output on what's happening" ), make_option( opt_str = c("-n", "--nrows"), dest = "nrows", type = "integer", default = 0, help = "number of rows from data to use, defaults to all of them", metavar = "4" ), make_option( opt_str = c("-i", "--index"), dest = "index", type = "integer", default = 0, help = "Which realization of resampled dataset", metavar = "4" ) , make_option( opt_str = c("-e", "--vegtype"), dest = "vegtype", type = "character", default = default.vegtype, help = "Which vegetation type? for, nonfor or all allowed", metavar = "4" ) ) parser <- OptionParser( usage = "Rscript %prog [options] data dt_beals header output", option_list = options, description = "\nan awesome R script", epilogue = "use with caution, the awesomeness might slap you in the face!" ) cli <- parse_args(parser, positional_arguments = 5) # ------------------------------------------------------------------------------ # assign a few shortcuts # ------------------------------------------------------------------------------ data <- cli$args[1] Mij <- cli$args[2] header <- cli$args[3] subset <- cli$args[4] output <- cli$args[5] ncores <- cli$options$ncores verbose <- cli$options$verbose nrows <- cli$options$nrows index <- cli$options$index vegtype <- cli$options$vegtype # ------------------------------------------------------------------------------ # actual program # ------------------------------------------------------------------------------ source("A01_SpeciesPool_sPlot.R") SpeciesPool_sPlot(data, Mij, header, subset, output, ncores, verbose, nrows, index, vegtype)