v_xypair() returns a validator function that checks if a value is a list
with paired x and y components of equal length. This is useful for
validating paired data structures in options managers created with
create_options_manager().
v_xypair(min_len = 1)A validator function that takes a value (typically a list with x
and y components) and raises an error if:
The value is not a list
The list does not contain both x and y named elements
Either x or y is NULL
Either x or y is not an atomic vector
Either x or y contains NA values
The x and y vectors have different lengths
The vectors are shorter than min_len
# Create a validator for XY pairs with minimum length 2
validator <- v_xypair(min_len = 2)
# Valid input
validator(list(x = c(1, 2, 3), y = c(10, 20, 30)))
# Invalid inputs (would raise errors)
try(validator(list(x = c(1), y = c(10))))
#> Error : xypair length must be >= 2
try(validator(list(x = c(1, 2), y = c(10, 20, 30)))) # different lengths
#> Error : 'x' and 'y' must have the same length
try(validator(list(x = c(1, NA), y = c(10, 20)))) # contains NA
#> Error : 'x' and 'y' must not contain NA values
try(validator(list(x = c(1, 2)))) # missing y
#> Error : xypair must contain both 'x' and 'y'