vec_size(x) returns the size of a vector.
TRUE if the size is zero,
The size is distinct from the
length() of a vector because it
generalises to the "number of observations" for 2d structures,
i.e. it's the number of rows in matrix or a data frame. This
definition has the important property that every column of a data
frame (even data frame and matrix columns) have the same size.
vec_size_common(...) returns the common size of multiple vectors.
vec_size(x) vec_size_common(..., .size = NULL, .absent = 0L) vec_is_empty(x)
Vector inputs or
The size used when no input is provided, or when all input
An integer (or double for long vectors).
.absent if all inputs are
0L by default.
There is no vctrs helper that retrieves the number of columns: as this is a property of the type.
vec_size() is equivalent to
NROW() but has a name that is easier to
pronounce, and throws an error when passed non-vector inputs.
vec_size(matrix[, i, drop = FALSE])
vec_size(vec_c(x, y)) ==
The size of
NULL is hard-coded to
.absent when all inputs are
(if only some inputs are
NULL, they are simply ignored).
A default size of 0 makes sense because sizes are most often
queried in order to compute a total size while assembling a
collection of vectors. Since we treat
NULL as an absent input by
principle, we return the identity of sizes under addition to
reflect that an absent input doesn't take up any size.
Note that other defaults might make sense under different circumstances. For instance, a default size of 1 makes sense for finding the common size because 1 is the identity of the recycling rules.
vec_size(1:100)#>  100vec_size(mtcars)#>  32#>  3vec_size_common(1:10, 1:10)#>  10vec_size_common(1:10, 1)#>  10vec_size_common(1:10, integer())#>  0