Learn R Programming

optigrab (version 0.9.2.1)

opt_fill: opt_fill

Description

Fill a recursive structure with command-line arguments

Usage

opt_fill(x, opts = commandArgs(), style = getOption("optigrab")$style)

Arguments

x

list-like (recursive)) object with names to use as a template.

opts

character command-line option list (Default: commandArgs() )

style

string; the command-line style (Default: getOption('optigrab')$style

Value

(A copy of) x, with values filled from the command-line. If x is a reference structure, this is done by reference, returning the object invisibly.

Details

opt_fill uses x as a template of values to be retrieved. Named elements of x are retrieved from the command line using opt_get(). Values are coerced to the type/class of the elements of x.

This gives a handy way of defining and retrieving all setting at once overridding the defaults.

opt_fill is similar to utils::modifyList() but does not work recursively.

See Also

opt_get() utils::modifyList()

Examples

Run this code
# NOT RUN {
  defaults <- list( foo="a", bar=1 )
  
  opt_fill( defaults, opts=c( '--foo', 'command-line-foo' ))
  opt_fill( defaults, opts=c( '--foo', 'command-line-foo', '--bar', '9999' ))
 
  defaults <- as.environment(defaults)
  opt_fill( defaults, opts=c( '--foo', 'env-fill', '--bar', '555' ))
  
  str( as.list(defaults) )

# }

Run the code above in your browser using DataLab