R/check_missing.R

Defines functions assert_missing check_missing

Documented in assert_missing check_missing

#' Check missing formal argument
#'
#' @description
#' These functions check whether a value was specified as an argument to a
#' function.
#'
#' @param x \[`any`\]\cr
#' A formal argument.
#'
#' @return
#' TODO
#'
#' @keywords validation
#' @family package helpers
#' @export
#'
#' @examples
#' f <- function(x) {
#'   check_missing(x)
#' }
#' f()
#'
#' g <- function(x) {
#'   test_missing(x)
#' }
#' g()
#'
#' h <- function(x) {
#'   assert_missing(x)
#' }
#' \dontrun{
#' h()
#' }

check_missing <- function(x) {
  x_missing <- missing(x)
  if (isTRUE(x_missing)) {
    return("Argument needs a value")
  }
  return(TRUE)
}

#' @rdname check_missing
#' @export

assert_missing <- function(x) {
  checkmate::makeAssertion(
    x,
    check_missing(x),
    checkmate::vname(x),
    NULL
  )
}

#' @rdname check_missing
#' @export

test_missing <- checkmate::makeTestFunction(
  check_missing
)

Try the oeli package in your browser

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

oeli documentation built on June 8, 2025, 11:40 a.m.