This function returns the number of environments between env and the empty environment, including env. The depth of env is also the number of parents of env (since the empty environment counts as a parent).

env_depth(env)

Arguments

env

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

Value

An integer.

See also

The section on inheritance in env() documentation.

Examples

env_depth(empty_env())
#> [1] 0
env_depth(pkg_env("rlang"))
#> [1] 12