The document discusses the Getopt::Long module for parsing command line arguments in R. It provides an example of using Getopt::Long to parse arguments in an R script called getopt_long_sample.R, where the --save.path argument is parsed and assigned to the save.path variable. Getopt::Long allows defining argument types like strings, integers, and flags to parse command line options consistently in both Perl and R scripts.
Upgrade Your Banking Experience with Advanced Core Banking Applications
R版Getopt::Longを作ってみた
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)
}