R/chk-not-null.R

Defines functions vld_not_null chk_not_null

Documented in chk_not_null vld_not_null

#' Check not NULL
#'
#' @description
#' Checks if not NULL using
#'
#' `!is.null(x)`
#'
#' @inheritParams params
#' @inherit params return
#'
#' @family chk_nulls
#'
#' @examples
#' # chk_not_null
#' try(chk_not_null(NULL))
#' chk_not_null(1)
#' @export
chk_not_null <- function(x, x_name = NULL) {
  if (vld_not_null(x)) {
    return(invisible(x))
  }
  if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
  abort_chk(x_name, " must not be NULL", x = x)
}

#' @describeIn chk_not_null Validate Not NULL
#'
#' @examples
#' # vld_not_null
#' vld_not_null(1)
#' vld_not_null(NULL)
#' @export
vld_not_null <- function(x) !is.null(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.