v_character_vector() returns a validator function that checks if a value is a character vector meeting specified length requirements. This is useful for options requiring character sequences or lists of strings.

v_character_vector(min_len = 1)

Arguments

min_len

Minimum length required for the vector. Defaults to 1.

Value

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

  • x is not character

  • x has fewer than min_len elements

Examples

# Create a validator for character vectors of at least length 1
validator <- v_character_vector()

# Valid input
validator(c("hello"))
validator(c("hello", "world"))

# Invalid inputs (would raise errors)
try(validator(character(0)))  # too short
#> Error : length must be >= 1
try(validator(c(1, 2, 3)))  # not character
#> Error : must be character

# Create a validator allowing empty vectors
validator_empty <- v_character_vector(min_len = 0)
validator_empty(character(0))  # valid