Update lists of parameters

Description

Joining or updating lists of parameters.

Usage

1
2
3
4
5
6
7
  updateList(input, update, ignoreNULLs = TRUE)

  updateNULLs(input, update, ignoreNULLs = TRUE)

  updateMissing(input, update, ignoreNULLs = TRUE)

  updateJoin(input, update, ignoreNULLs = FALSE)

Arguments

input

style list of input parameters to be updated

update

style list of updates

ignoreNULLs

logical, if TRUE ignore NULL values in list update

Details

updateList replaces values of any elements in input that also are contained in update with new values from update.

updateNULLs works like updatelist, however only NULL values are replaced, other values remain untouched. The value of ignoreNULLs does not really matter here.

updateMissing complements the list input by elements in update, but does not change existing values in input, even if they are NULLs.

updateJoin returns a merged list of input and update, with priority of non-NULL values contained in update. The result of updatejoin(A, B) is almost the same as updateMissing(B, A), up to not forcing to preserve NULL values in B. By default, ignoreNULLs is set to FALSE here, thus the result also contains NULL elements from update, if no element with same name was present in input.

Value

A style list with updated values, see the Details

Author(s)

Ute Hahn, ute@imf.au.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
A <- style(a = NULL, b = "b from A", c = "c from A", d = "d from A")
B <- style(a = "a from B", b = "b from B", c =  NULL,
         e = "e from B", f = NULL)

str(updateList(A, B))
# sequence does not matter:
str(updateList(A[c(3, 2, 1)], B))
# forcing new NULL values
str(updateList(A, B, ignoreNULLs = FALSE))

str(updateNULLs(A, B))

str(updateMissing(A, B))
str(updateMissing(A, B, ignoreNULLs = FALSE))

str(updateJoin(A, B))
str(updateJoin(A, B, ignoreNULLs = TRUE))
# this can be used to remove NULL values from a list:
str(updateJoin(A, NULL, ignoreNULLs = TRUE))