Recursively Modify Elements of a List
Modifies a possibly nested list recursively by changing a subset of elements at each level to match a second list.
modifyList(x, val, keep.null = FALSE)
- A named
list, possibly empty.
- A named list with components to replace corresponding
x. Otherwise, the corresponding element, if present, is deleted from
A modified version of
x, with the modifications determined as follows (here, list elements are identified by their names). Elements in
valwhich are missing from
xare added to
x. For elements that are common to both but are not both lists themselves, the component in
xis replaced (or possibly deleted, depending on the value of
keep.null) by the one in
val. For common elements that are in both lists,
x[[name]]is replaced by
foo <- list(a = 1, b = list(c = "a", d = FALSE)) bar <- modifyList(foo, list(e = 2, b = list(d = TRUE))) str(foo) str(bar)
Looks like there are no examples yet.