R/chk-not-missing.R

Defines functions vld_not_missing chk_not_missing

Documented in chk_not_missing vld_not_missing

#' Check Not Missing Argument
#'
#' @description
#' Checks argument not missing using
#'
#' `!missing(x)`
#'
#' @details
#' Currently only checks if value is available
#' (as opposed to whether it was specified).
#'
#' @inheritParams params
#' @inherit params return
#'
#' @family chk_misc
#'
#' @examples
#' # chk_not_missing
#' fun <- function(x) {
#'   chk_not_missing(x)
#' }
#' fun(1)
#' try(fun())
#' @export
chk_not_missing <- function(x, x_name = "`x`") {
  if (vld_not_missing(x)) {
    return(invisible(x))
  }
  abort_chk(x_name, " must not be missing.", tidy = FALSE)
}

#' @describeIn chk_not_missing Validate Not Missing Argument
#'
#' @examples
#' # vld_not_missing
#' fun <- function(x) {
#'   vld_not_missing(x)
#' }
#' fun()
#' fun(1)
#' @export
vld_not_missing <- function(x) {
  !missing(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.