env_unbind() is the complement of env_bind(). Like env_has(), it ignores the parent environments of env by default. Set inherit to TRUE to track down bindings in parent environments.

env_unbind(env = caller_env(), nms, inherit = FALSE)

Arguments

env

An environment or an object bundling an environment, e.g. a formula, quosure or closure.

nms

A character vector containing the names of the bindings to remove.

inherit

Whether to look for bindings in the parent environments.

Value

The input object env, with its associated environment modified in place.

Examples

data <- set_names(as_list(letters), letters) env_bind(environment(), !!! data)
#> <environment: 0x7f979f246838>
env_has(environment(), letters)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
# env_unbind() removes bindings: env_unbind(environment(), letters)
#> <environment: 0x7f979f246838>
env_has(environment(), letters)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [25] FALSE FALSE
# With inherit = TRUE, it removes bindings in parent environments # as well: parent <- child_env(NULL, foo = "a") env <- child_env(parent, foo = "b") env_unbind(env, "foo", inherit = TRUE)
#> <environment: 0x7f97a0886dc0>
env_has(env, "foo", inherit = TRUE)
#> [1] FALSE