commandArgs() looks like this:
> commandArgs()  "R" "--no-save" "--no-restore-data" "--gui=aqua"
Minimist turns that into this:
> library(minimist) > minimist(commandArgs()) $`_`  "R" $save  FALSE $`restore-data`  FALSE $gui  "aqua"
Note how it interprets the
--no- prefix as
FALSE and the
--foo=bar as a key-value pair. It has some more of these rules, following the usual scripting argument syntax conventions. Cool, but not exactly ground breaking; there are already half a dozen packages on CRAN for parsing arguments (although this one is particularly nice :P).
- A copy of the minimist.js library in the package
- Two lines of standard code to initiate the V8 engine and read minimist when loading the R package
That’s it. To install this package from source no compiler is required. It will build out of the box, even on machines without Rtools or Xcode. Moreover, there are no external dependencies as is the case for e.g. Java code, where we need to install a JVM. Everything is self contained within R and V8. It’s fast too:
> system.time(minimist(commandArgs())) user system elapsed 0.001 0.000 0.001