Description Usage Arguments Details Value Author(s)
The idea is that to write a command line utility with R, you just write a main() function use Rscript as your hashbang interpreter, and at the end of your R script call run_as_command.
1 2 3 | run_as_command(func = parent.frame()$main,
arguments = commandArgs(trailingOnly = TRUE), require.toplevel = TRUE,
require.noninteractive = TRUE)
|
func |
Which function to invoke. Defaults to whatever "main" function is defined in the calling scope. |
arguments |
The command line arguments to parse. By default, uses commandArgs(trailingOnly=TRUE) |
require.toplevel |
Only run if invoked from the top level, as from Rscript. |
require.noninteractive |
Only run if in a non-interactive R session. |
TODO: Named arguments given with two dashes, GNU style, will be translated into named arguments passed to the function. A bare double dash means to discontinue named-argument parsing for the rest of the command line.
TODO: A help argument will be constructed according to the Roxygen documentation for the function.
Nothing. Things printed will naturally go out stdout and errors during execution will naturally result in a nonzero exit code.
Peter Meilstrup
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.