1. R Getopt::Long
Tsukuba.R #9 (2011/11/12)
@a_bicky
14. parseArgs <- function() {
argv <- commandArgs(trailingOnly = TRUE)
argv <- strsplit(argv, "=")
argv <- sapply(argv, function(arg) {
ret <- ifelse(is.na(arg[2]), 1, arg[2])
names(ret) <- arg[1]
return(ret)
})
# show usage
# Not use 'existsFunction' because loading 'methods' package
takes about 60% of the startup time
if ("help" %in% names(argv)) {
tryCatch(usage(), error = function(e) cat("No usage for
this scriptn"))
quit()
}
# check arguments
# Not use 'existsFunction' because loading 'methods' package
takes about 60% of the startup time
try(checkArgs(argv), silent = TRUE)
return(argv)
}