Learn R Programming

rlang (version 0.2.1)

duplicate: Duplicate an R object

Description

In R semantics, objects are copied by value. This means that modifying the copy leaves the original object intact. Since, copying data in memory is an expensive operation, copies in R are as lazy as possible. They only happen when the new object is actually modified. However, some operations (like node_poke_car() or node_poke_cdr()) do not support copy-on-write. In those cases, it is necessary to duplicate the object manually in order to preserve copy-by-value semantics.

Usage

duplicate(x, shallow = FALSE)

Arguments

x

Any R object. However, uncopyable types like symbols and environments are returned as is (just like with <-).

shallow

This is relevant for recursive data structures like lists, calls and pairlists. A shallow copy only duplicates the top-level data structure. The objects contained in the list are still the same.

Details

Some objects are not duplicable, like symbols and environments. duplicate() returns its input for these unique objects.

See Also

pairlist