Skip to content

Instantly share code, notes, and snippets.

@kevinrue
Last active March 26, 2019 14:39
Show Gist options
  • Save kevinrue/37c275521a97e94b1491cd946758fa39 to your computer and use it in GitHub Desktop.
Save kevinrue/37c275521a97e94b1491cd946758fa39 to your computer and use it in GitHub Desktop.
Template for Rscript
# Introduction -----
timestamp()
message("Started")
# Packages ----
stopifnot(suppressPackageStartupMessages({
require(optparse)
}))
# Test options ----
opt <- list(
long_flag="if_applicable"
)
# Parse options ----
option_list <- list(
make_option(
c("--longflag", "-s"), action="store",
# type=c("character", "integer", "logical", "double", "complex"),
dest="long_flag",
default="if_applicable",
help="Description of input option")
)
opt <- parse_args(OptionParser(option_list=option_list))
message("Running with options:")
print(opt)
cat("Debug:\nopt <- ", fill = FALSE); cat(deparse(opt), fill=80)
# Process data ----
cat("Doing something ... ")
do_something <- TRUE
cat("Done.\n")
stop("Change me!")
# Conclusion ---
message("Completed")
timestamp()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment