R/check_types.R

Defines functions .check_types

#' Check types
#'
#' @param x object to check
#' @param types allowed types
#' @param msg error message
#'
#' @keywords internal
#' @noRd
#'
#' @return list version of input
.check_types <- function(x, types, msg = "Incorrect type") {
  err <- FALSE
  if (inherits(x, types)) {
    x <- list(x)
  } else if (inherits(x, "list")) {
    if (!all(sapply(x, inherits, types))) {
      err <- TRUE
    }
  } else {
    err <- TRUE
  }
  if (err) stop(msg, call. = FALSE)
  x
}

Try the GeoTox package in your browser

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

GeoTox documentation built on April 4, 2025, 5:07 a.m.