R/check-length.R

Defines functions check_length

Documented in check_length

#' Check Length
#'
#' @description
#' Checks length of an object.
#'
#' @inheritParams params
#' @param values A flag or a whole numeric vector of the value, value range or possible values.
#' @return An informative error if the test fails or an invisible copy of x.
#'
#' @family check
#'
#' @examples
#' check_length(1)
#' try(check_length(1, values = FALSE))
#' try(check_length(1, values = c(10, 2)))
#' @export
check_length <- function(x, values = numeric(0), x_name = NULL) {
  if (is.null(x_name)) x_name <- deparse((substitute(x)))
  check_dim(x, values = values, x_name = x_name, dim_name = "length")
}

Try the chk package in your browser

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

chk documentation built on April 3, 2025, 8:50 p.m.