library(optparse) # ------------------------------------------------------------------------------ # defaults # ------------------------------------------------------------------------------ default.max.inter.t <- 1 default.nperm <- 99 default.ncores <- 1 # ------------------------------------------------------------------------------ # parsing arguments # ------------------------------------------------------------------------------ options <- list ( make_option( opt_str = c("-c", "--ncores"), 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("-m", "--max.inter.t"), dest = "max.inter.t", type = "integer", default = default.max.inter.t, help = "Max number of interactions for traits", metavar = "4" ), make_option( opt_str = c("-n", "--chunkn"), dest = "chunkn", type = "integer", default = 1, help = "How many chunks?", metavar = "4" ), make_option( opt_str = c("-i", "--chunk.i"), dest = "chunk.i", type = "integer", default = NA, help = "Which chunk?", metavar = "4" ), make_option( opt_str = c("-p", "--nperm"), dest = "nperm", type = "integer", default = default.nperm, help = "How many permutations?", 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 = 4) # ------------------------------------------------------------------------------ # assign a few shortcuts # ------------------------------------------------------------------------------ species.path <- cli$args[1] traits.path <- cli$args[2] output <- cli$args[3] myfunction <- cli$args[4] combinations <- cli$args[5] max.inter.t <- cli$options$max.inter.t chunkn <- cli$options$chunkn chunk.i <- cli$options$chunk.i nperm <- cli$options$nperm ncores <- cli$options$ncores # ------------------------------------------------------------------------------ # actual program # ------------------------------------------------------------------------------ source("01b_MesobromionCluster.R") Mesobromion(species.path, traits.path, output, myfunction, combinations, max.inter.t, chunkn, chunk.i, nperm) Mesobromion(species.path, traits.path, output, myfunction, combinations, max.inter.t, chunkn, chunk.i, nperm, ncores)