expand_list(x, ..., .exact = TRUE, .names = !.exact) expand_dots(..., .exclude = NULL)
x
should be partially matched against the
defaults..exact=FALSE
and indicates that the names of items
in x
that partially match some defaults should be
expanded in the returned list.a list
expand_list
expands a named list with a given set
of default items, if these are not already in the list,
partially matching their names.
expand_dots
expands the ...
arguments of
the function in which it is called with default values,
using expand_list
. It can only be called
from inside a function.
expand_list(list(a=1, b=2), c=3)$a [1] 1 $b [1] 2 $c [1] 3expand_list(list(a=1, b=2, c=4), c=3)$a [1] 1 $b [1] 2 $c [1] 4# with a listexpand_list(list(a=1, b=2), list(c=3, d=10))$a [1] 1 $b [1] 2 $c [1] 3 $d [1] 10# no partial matchexpand_list(list(a=1, b=2, c=5), cd=3)$a [1] 1 $b [1] 2 $c [1] 5 $cd [1] 3# partial match with names expandedexpand_list(list(a=1, b=2, c=5), cd=3, .exact=FALSE)$a [1] 1 $b [1] 2 $cd [1] 5# partial match without expanding namesexpand_list(list(a=1, b=2, c=5), cd=3, .exact=FALSE, .names=FALSE)$a [1] 1 $b [1] 2 $c [1] 5# works also inside a function to expand a call with default argumentsf <- function(...){ cl <- match.call() expand_list(cl, list(a=3, b=4), .exact=FALSE) }f()f(a = 3, b = 4)f(c=1)f(c = 1, a = 3, b = 4)f(a=2)f(a = 2, b = 4)f(c=1, a=2)f(c = 1, a = 2, b = 4)# expanding dot argumentsf <- function(...){ expand_dots(list(a=2, bcd='a', xxx=20), .exclude='xxx') }# add default value for all argumentsf()$a [1] 2 $bcd [1] "a"# add default value for `bcd` onlyf(a=10)$a [1] 10 $bcd [1] "a"# expand namesf(a=10, b=4)$a [1] 10 $bcd [1] 4