Skip to content

expect_vector() is a thin wrapper around vctrs::vec_assert(), converting the results of that function in to the expectations used by testthat. This means that it used the vctrs of ptype (prototype) and size. See details in


expect_vector(object, ptype = NULL, size = NULL)



Object to test.

Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details.


(Optional) Vector prototype to test against. Should be a size-0 (empty) generalised vector.


(Optional) Size to check for.


if (requireNamespace("vctrs") && packageVersion("vctrs") > "") {
expect_vector(1:10, ptype = integer(), size = 10)
show_failure(expect_vector(1:10, ptype = integer(), size = 5))
show_failure(expect_vector(1:10, ptype = character(), size = 5))
#> Failed expectation:
#> `1:10` must have size 5, not size 10.
#> Failed expectation:
#> `1:10` must be a vector with type <character>.
#> Instead, it has type <integer>.