R/zzz.R

Defines functions check_for_package `%||%` assert cpt

cpt <- function(l) Filter(Negate(is.null), l)

assert <- function(x, y) {
  if (!is.null(x)) {
    if (!inherits(x, y)) {
      stop(deparse(substitute(x)), " must be of class ",
           paste0(y, collapse = ", "), call. = FALSE)
    }
  }
}

`%||%` <- function(x, y) if (is.null(x)) y else x

check_for_package <- function(x) {
  if (!requireNamespace(x, quietly = TRUE)) {
    stop(sprintf("Please install '%s'", x), call. = FALSE)
  } else {
    invisible(TRUE)
  }
}
ropensci/clock documentation built on Sept. 11, 2022, 11:07 a.m.