Created
December 11, 2017 18:47
-
-
Save patr1ckm/5d997f46f99180ab5910fc1122569783 to your computer and use it in GitHub Desktop.
docopt.R demo
This file contains 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
#!/usr/local/bin/Rscript | |
'usage: my_prog.R [-a -r -m <msg>] | |
options: | |
-a Add | |
-r Remote | |
-m <msg> Message' -> doc | |
library(docopt) | |
opts <- docopt(doc) | |
system("touch alog.txt") | |
prev_msg <- readLines("alog.txt") | |
where <- if (opts[["-r"]]) "REMOTE: " else "LOCAL: " | |
msg <- if (!is.null(opts[["-m"]])) opts[["-m"]] else "<empty>" | |
final_msg <- c(prev_msg, paste0(where, msg)) | |
if (opts[["-a"]]) cat(final_msg, file = "alog.txt", sep="\n", append = FALSE) | |
cat(final_msg, sep = "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: