A vecvec is a vector that holds elements of different types without
coercing them to a common type. Unlike a list of vectors, a vecvec behaves
as a flat vector (hence vector of vectors). This means that you can
operations (such as indexing, arithmetic, and statistics) apply across all
elements of a vecvec as if they were combined into a single vector.
Mixed-type vectors can be useful if you need to store heterogeneous data in a vector-like structure. In most cases, I believe this is bad practice for data analytics, but this could be useful for tidying up messy data. The most valuable use case for vecvec is as a data structure for mixed-type semantic vectors. This package is used by mixtime and distributional to create vectors of time with different chronons and distributions with different shapes.
To convert a vecvec back to a plain typed vector, use unvecvec(), which
casts all elements to a common type via vctrs::vec_cast().
vecvec(...)A vecvec object whose length equals the total number of elements
across all input vectors.
unvecvec() to coerce a vecvec to a single-typed vector;
is_vecvec() to test whether an object is a vecvec.
# Mixed types are preserved without coercion
vv <- vecvec(Sys.Date(), rnorm(3), letters)
vv
#> <vecvec[30]>
#> [1] 2026-04-27 0.4681544 0.3629513 -1.3045435 a b
#> [7] c d e f g h
#> [13] i j k l m n
#> [19] o p q r s t
#> [25] u v w x y z
# .[i] Indexing works like a flat vector
vv[c(1L, 3L, 7L)]
#> <vecvec[3]>
#> [1] 2026-04-27 0.3629513 c
# .[[i]] drops to the original vector type
vv[[2L]]
#> [1] 0.4681544