R/environment_of.R

Defines functions environment_of

# A safe version of base::environment() that returns emptyenv()
# if NULL is passed, instead of the calling environment.
# Related to https://github.com/HenrikBengtsson/globals/issues/79
environment_of <- function(obj) {
  if (is.null(obj)) return(emptyenv())
  e <- environment(obj)
  if (is.null(e)) return(emptyenv())
  e
}

Try the globals package in your browser

Any scripts or data that you put into this service are public.

globals documentation built on Nov. 22, 2022, 1:10 a.m.