Checks length of an object is within bounds.

check_length(
  x,
  min_length = 1L,
  max_length = max_integer(),
  x_name = substitute(x)
)

Arguments

x

The object to check.

min_length

A count of the minimum length.

max_length

A count of the maximum length.

x_name

A string of the name of the object.

Value

Throws an informative error or returns an invisible copy of the object.

Examples

try(check_length(1:2, 3L))
#> Error : 1:2 must be at least of length 3