R/calling_env.R

Defines functions calling_env

#' Get the First (Non squr) Calling Environment
#'
#' @return Environment
#' @noRd
calling_env <- function()
{
  top        <- topenv(environment(calling_env))
  frames     <- c(.GlobalEnv, sys.frames())
  topenvs    <- lapply(frames, topenv)
  is_squr    <- vapply(topenvs, function(e) identical(e, top), logical(1))
  first_squr <- min(which(is_squr))

  frames[[first_squr - 1]]
}
smbache/squr documentation built on May 15, 2021, 3:45 a.m.