Last active
March 26, 2019 14:39
-
-
Save kevinrue/37c275521a97e94b1491cd946758fa39 to your computer and use it in GitHub Desktop.
Template for Rscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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