Learn R Programming

rlang (version 0.1)

env_get: Get an object from an environment

Description

env_get() extracts an object from an enviroment env. By default, it does not look in the parent environments.

Usage

env_get(env = caller_env(), nm, inherit = FALSE)

Arguments

env

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

nm

The name of a binding.

inherit

Whether to look for bindings in the parent environments.

Value

An object if it exists. Otherwise, throws an error.

Examples

Run this code
# NOT RUN {
parent <- child_env(NULL, foo = "foo")
env <- child_env(parent, bar = "bar")

# This throws an error because `foo` is not directly defined in env:
# env_get(env, "foo")

# However `foo` can be fetched in the parent environment:
env_get(env, "foo", inherit = TRUE)
# }

Run the code above in your browser using DataLab