assertive.code (version 0.0-3)

assert_is_binding_locked: 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))

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.

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.

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

Run this code
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)

Run the code above in your browser using DataLab