Learn R Programming

container (version 1.0.5)

update: Update Object with Elements from Another Object

Description

Takes an object and updates it with values from another object by replacing the values at existing names and adding values at new names of the other object. A common use case is to update parameter lists.

Usage

ref_update(object, other, ...)

# S3 method for Container update(object, other, ...)

# S3 method for Container ref_update(object, other, ...)

# S3 method for dict.table update(object, other, ...)

# S3 method for dict.table ref_update(object, other, ...)

# S3 method for list update(object, other, ...)

Value

For Container, an object of class Container (or one of the respective derived classes).

For dict.table an object of class dict.table.

For list, an updated object of class list.

Arguments

object

any R object

other

any object of the same type as object

...

additional arguments to be passed to or from methods.

Details

update uses copy semantics while ref_update works by reference, that is, updates in place.

Examples

Run this code

d1 = dict(a = 1, b = 2)
d2 = dict(       b = 0, c = 3)
update(d1, d2)  # {a = 1, b = 0, c = 3}
update(d2, d1)  # {a = 1, b = 2, c = 3}

dit1 = dict.table(a = 1:2, b = 3:4)
dit2 = dict.table(         b = 5:6, c = 8:9)
update(d1, d2)
update(d2, d1)

l1 = list(1, b = 2)
l2 = list(   b = 0, c = 3)
update(l1, l2)
update(l2, l1)

Run the code above in your browser using DataLab