overwrite_list: Overwrites a list with named arguments

Description Usage Arguments Details

Description

Returns a list that is the intersection of defaults and ... where named values in ... overwrite values in defaults.

Usage

1
overwrite_list(defaults, ...)

Arguments

defaults

list of default values. Argument always be specified by name not position

...

a comma separated set of named

overwrite_list(defaults = list(a = 1, b = '2'), c = 1, a = '3') will return list(a = '1', b = '2', c = 1)

To demonstrate the operation when one of the arguments is a pairlist, note that both of the functions below produce the same result. You can either pass the elipsis (...) directly, or you can extract the arguments from the call and pass them later.

f = function(...) { overwrite_list(defaults = list(a = 1, b = 'b'), b = 2, ...) }

f = function(...) { # Extract passed arguments from call dot_args = match.call(expand.dots = F)$... overwrite_list(defaults = list(a = 1, b = 'b'), b = 2, dot_args) }

f(k = 5) will return list(a = 1, b = 2, k = 5).

f(b = 10) will return list(a = 1, b = 10). Note how the named argument b appears 3 times in the overwrite_list call; once in the defaults, once explicitly specified for overwriting (b = 2), and once indirectly specified via the arguments to f (b = 10).

Details

One or more of the elements in ... can be a pairlist (the structure in which dotted arguments are stored) and this list will get expanded and substituted into defaults too. This means that the same named argument could be listed more than twice, in which case the right-most value is used. See below for details.


jongbinjung/undi documentation built on May 8, 2019, 11:56 p.m.