Skip to contents

Checks length of an object.

Usage

check_length(x, values = numeric(0), x_name = NULL)

Arguments

x

The object to check.

values

A flag or a whole numeric vector of the value, value range or possible values.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See also

Examples

check_length(1)
try(check_length(1, values = FALSE))
#> Error in check_dim(x, values = values, x_name = x_name, dim_name = "length") : 
#>   `length(1)` must be equal to 0L.
#> Use `rlang::last_error()$y` to show the object compared to.
try(check_length(1, values = c(10, 2)))
#> Error in check_dim(x, values = values, x_name = x_name, dim_name = "length") : 
#>   `length(1)` must be between 2 and 10, not 1.