Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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


rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.