Update the elements of a list

Share:

Description

Function to update the elements of a list to contain all of the named elements of a new list, overwriting elements with the same name, and (optionally) copying unnamed elements.

Usage

1
2
3
4
5
update.list(object, new, unnamed=FALSE, ...)
## S3 method for class 'list'
update(object, new, unnamed=FALSE, ...)
## S3 method for class 'data.frame'
update(object, new, unnamed=FALSE, ...)

Arguments

object

List to be updated.

new

List containing new elements.

unnamed

Logical. If TRUE, unnamed elements of new will be appended to object

...

optional method arguments (ignored)

Value

A constructed from the elements of object, with named elements of new replacing corresponding named elements from object, and non-corresponding elements of new appended. If unnamed=TRUE, unnamed elements of new will be appended.

Note

This method can be called directly, or as via the S3 base method for update.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

update, merge

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
old <- list(a=1,b="red",c=1.37)
new <- list(b="green",c=2.4)

update(old, new)
update.list(old,new)  # equivalent

older <- list(a=0, b="orange", 4, 5, 6)
newer <- list(b="purple", 7, 8, 9)
update(older, newer)               # ignores unnamed elements of newer
update(older, newer, unnamed=TRUE) # appends unnamed elements of newer

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.