sl.read.args: Read Named Arguments in Batch Mode

sl.read.argsR Documentation

Read Named Arguments in Batch Mode

Description

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.

Usage

sl.read.args(sep = ",", missval = NULL)

Arguments

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.

Value

A character list with the arguments, named according to the argument names. Returns NULL if no arguments are found.

Author(s)

Helge Goessling

Examples

##    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() .

FESOM/spheRlab documentation built on March 7, 2024, 8:39 a.m.