options(stringsAsFactors = FALSE)
## load the libraries
library(optparse)
## create the options
parser <- OptionParser()
parser <- add_option(parser, c("-c", "--count"),
type="integer",
default = 5,
help = "How many things to return")
## parse the things
cargs = parse_args(parser)
## do the thing
runif(cargs$count)
To run the script:
```
Rscript command-testing.R
```
and this will return the following within the terminal
```
[1] 0.6045390 0.8331392 0.7229302 0.1976436 0.3871353
```
# About
A quick script to explore one of the options for using command line args for an
R script.
https://twitter.com/BrockTibert/status/1076844910022660096
- good quick review:
-- http://blog.sellorm.com/2017/12/30/command-line-utilities-in-r-pt-6/