is_binding_locked: Is the binding of a variable locked?

View source: R/is-code.R

assert_is_binding_lockedR Documentation

Is the binding of a variable locked?

Description

Check to see if the binding of a variable is locked (that is, it has been made read-only).

Usage

assert_is_binding_locked(x, severity = getOption("assertive.severity", "stop"))

is_binding_locked(
  x,
  env = if (is_scalar(e <- find(.xname))) as.environment(e) else parent.frame(),
  .xname = get_name_in_parent(x)
)

Arguments

x

Input to check. (Unlike bindingIsLocked, you can pass the variable itself, rather than a string naming that variable.)

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

env

Environment to check where binding had been locked.

.xname

Not intended to be used directly.

Value

TRUE or FALSE, depending upon whether or not the binding is locked in the specified environment. assert_is_binding_locked returns nothing but throws an error if the corresponding is_* function returns FALSE.

Note

The environment is guessed as follows: The name of x is determined via get_name_in_parent. Then find is called,

See Also

bindingIsLocked, which this wraps, find for how the environment is guessed. If this returns a single environment, that is used. Otherwise the parent environment is used (as determined with parent.frame).

Examples

is_binding_locked(a_non_existent_variable)
e <- new.env()
e$x <- 1:10
is_binding_locked(x, e)
lockBinding("x", e)
is_binding_locked(x, e)
unlockBinding("x", e)
is_binding_locked(x, e)

assertive.code documentation built on May 31, 2023, 5:35 p.m.