topenv
Top-Level Environment

Description

Searches an environment, its parent, and so on to find a "top-level" environment where functions normally would be defined.

Usage

topenv(envir = parent.frame(),
       matchThisEnv = getOption("topLevelEnvironment"))

Arguments

envir an environment to start the search.
matchThisEnv an environment. If this environment is found during the search, it is returned.

Details

A "top-level" environment is either the global environment, the base package environment, or a namespace environment for a loaded package.
Value
returns the top-level environment found when searching from envir, its parent, and so on.
See Also
globalenv, baseenv, parent.env, getNamespace, isNamespace.
Examples
# these enviroments are defined as top level environments
identical(topenv(globalenv()),globalenv())
identical(topenv(baseenv()),baseenv())
identical(topenv(getNamespace("base")),getNamespace("base"))

# search for first top-level environment e1 <- new.env(parent=baseenv()) e2 <- new.env(parent=e1) identical(topenv(e2), baseenv())

# specify matchThisEnv to stop the search identical(topenv(e2, matchThisEnv=e1), e1)

Package base version 6.1.4-13
Package Index