R/chk-environment.R

Defines functions vld_environment chk_environment

Documented in chk_environment vld_environment

#' Check Environment
#'
#' @description
#' Checks if environment using
#'
#' `is.environment(x)`
#'
#' @inheritParams params
#' @inherit params return
#'
#' @family chk_typeof
#'
#' @examples
#' # chk_environment
#' chk_environment(.GlobalEnv)
#' try(chk_environment(1))
#' @export
chk_environment <- function(x, x_name = NULL) {
  if (vld_environment(x)) {
    return(invisible(x))
  }
  if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x)))
  abort_chk(x_name, " must be an environment", x = x)
}

#' @describeIn chk_environment Validate Environment
#'
#' @examples
#' # vld_environment
#' vld_environment(1)
#' vld_environment(list(1))
#' vld_environment(.GlobalEnv)
#' vld_environment(environment())
#' @export
vld_environment <- function(x) is.environment(x)

Try the chk package in your browser

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

chk documentation built on Oct. 6, 2023, 9:06 a.m.