obj_is_vector(1)
# Data frames are vectors
obj_is_vector(data_frame())
# Bare lists are vectors
obj_is_vector(list())
# S3 lists are vectors if they explicitly inherit from `"list"`
x <- structure(list(), class = c("my_list", "list"))
obj_is_list(x)
obj_is_vector(x)
# But if they don't explicitly inherit from `"list"`, they aren't
# automatically considered to be vectors. Instead, vctrs considers this
# to be a scalar object, like a linear model returned from `lm()`.
y <- structure(list(), class = "my_list")
obj_is_list(y)
obj_is_vector(y)
# `obj_check_vector()` throws an informative error if the input
# isn't a vector
try(obj_check_vector(y))
# `vec_check_size()` throws an informative error if the size of the
# input doesn't match `size`
vec_check_size(1:5, size = 5)
try(vec_check_size(1:5, size = 4))
Run the code above in your browser using DataLab