v_numeric_vector() returns a validator function that checks if a value is a numeric vector meeting specified length and finiteness requirements. This is useful for options requiring numeric sequences or datasets.

v_numeric_vector(min_len = 1, finite = TRUE)

Arguments

min_len

Minimum length required for the vector. Defaults to 1.

finite

If TRUE (default), rejects non-finite values (Inf, -Inf, NaN). If FALSE, non-finite values are allowed.

Value

A validator function that takes a value x and raises an error if:

  • x is not numeric

  • x has fewer than min_len elements

  • x contains NA values

  • finite is TRUE and x contains non-finite values

Examples

# Create a validator for numeric vectors of at least length 3
validator <- v_numeric_vector(min_len = 3)

# Valid input
validator(c(1, 2, 3))
validator(c(0.5, 1.5, 2.5, 3.5))

# Invalid inputs (would raise errors)
try(validator(c(1, 2)))  # too short
#> Error : length must be >= 3
try(validator(c(1, NA, 3)))  # contains NA
#> Error : must not contain NA
try(validator(c(1, Inf, 3)))  # contains non-finite value
#> Error : must be finite
try(validator("not numeric"))  # not numeric
#> Error : must be numeric