sl.read.args | R Documentation |
Read arguments provided when a script is called from the command line through Rscript
. Based on R
function commandArgs
, but allowing to specify named arguments in the style <argname>,<arg>
, returning an accordingly named list.
sl.read.args(sep = ",", missval = NULL)
sep |
a character specifying the separator between argument names and their arguments. Default is ','. |
missval |
a character or NULL specifying which value is assigned to argument names where no argument follows. Default is NULL. |
A character list with the arguments, named according to the argument names. Returns NULL if no arguments are found.
Helge Goessling
## Consider the following two-lines script with file name 'script.R':
## ---
## library(spheRlab)
## sl.read.args()
## ---
## Invoking this script from the command line with
## ---
## Rscript script.R arg1name,5 arg2name,hello arg3name,3.1415926536
## ---
## yields
## ---
## $arg1name
## [1] "5"
##
## $arg2name
## [1] "hello"
##
## $arg3name
## [1] "3.1415926536"
## ---
## To convert numeric arguments, use e.g. as.numeric() .
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.