opt_fill: opt_fill

Description Usage Arguments Details Value See Also Examples

View source: R/opt_fill.R

Description

Fill a recursive structure with command-line arguments

Usage

1
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

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.

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.

See Also

opt_get() utils::modifyList()

Examples

1
2
3
4
5
6
7
8
9
  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) )

decisionpatterns/optigrab documentation built on Jan. 8, 2019, 3:28 a.m.