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

env_binding_lock

Lock or unlock environment bindings


Description

Experimental lifecycle

Locked environment bindings trigger an error when an attempt is made to redefine the binding.

Usage

env_binding_lock(env, nms = NULL)

env_binding_unlock(env, nms = NULL)

env_binding_are_locked(env, nms = NULL)

Arguments

env

An environment.

nms

Names of bindings. Defaults to all bindings in env.

Value

env_binding_are_unlocked() returns a logical vector as long as nms and named after it. env_binding_lock() and env_binding_unlock() return the old value of env_binding_are_unlocked() invisibly.

See Also

env_lock() for locking an environment.

Examples

# Bindings are unlocked by default:
env <- env(a = "A", b = "B")
env_binding_are_locked(env)

# But can optionally be locked:
env_binding_lock(env, "a")
env_binding_are_locked(env)

# If run, the following would now return an error because `a` is locked:
# env_bind(env, a = "foo")
# with_env(env, a <- "bar")

# Let's unlock it. Note that the return value indicate which
# bindings were locked:
were_locked <- env_binding_unlock(env)
were_locked

# Now that it is unlocked we can modify it again:
env_bind(env, a = "foo")
with_env(env, a <- "bar")
env$a

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.