vadr (version 0.01)

run_as_command: run_as_command Interpret command line arguments and invokes some function with them.

Description

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.

Usage

run_as_command(func = parent.frame()$main, arguments = commandArgs(trailingOnly = TRUE), require.toplevel = TRUE, require.noninteractive = TRUE)

Arguments

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.

Value

Nothing. Things printed will naturally go out stdout and errors during execution will naturally result in a nonzero exit code.

Details

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.