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

is_copyable

Is an object copyable?


Description

When an object is modified, R generally copies it (sometimes lazily) to enforce value semantics. However, some internal types are uncopyable. If you try to copy them, either with <- or by argument passing, you actually create references to the original object rather than actual copies. Modifying these references can thus have far reaching side effects.

Usage

is_copyable(x)

Arguments

x

An object to test.

Examples

# Let's add attributes with structure() to uncopyable types. Since
# they are not copied, the attributes are changed in place:
env <- env()
structure(env, foo = "bar")
env

# These objects that can only be changed with side effect are not
# copyable:
is_copyable(env)

structure(base::list, foo = "bar")
str(base::list)

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.