Interleave many vectors into one vectorSource:
vec_interleave() combines multiple vectors together, much like
but does so in such a way that the elements of each vector are interleaved
It is a more efficient equivalent to the following usage of
vec_interleave(x, y) == vec_c(x, y, x, y, ..., x[n], y[n])
vec_interleave( ..., .ptype = NULL, .name_spec = NULL, .name_repair = c("minimal", "unique", "check_unique", "universal") )
Vectors to interleave. These will be recycled to a common size.
NULL, the default, the output type is determined by computing the common type across all elements of
Alternatively, you can supply
.ptypeto give the output known type. If
TRUEyou must supply this value: this is a convenient way to make production code demand fixed types.
A name specification for combining inner and outer names. This is relevant for inputs passed with a name, when these inputs are themselves named, like
outer = c(inner = 1), or when they have length greater than 1:
outer = 1:2. By default, these cases trigger an error. You can resolve the error by providing a specification that describes how to combine the names or the indices of the inner vector with the name of the input. This specification can be:
A function of two arguments. The outer name is passed as a string to the first argument, and the inner names or positions are passed as second argument.
An anonymous function as a purrr-style formula.
A glue specification of the form
rlang::zap()object, in which case both outer and inner names are ignored and the result is unnamed.
See the name specification topic.
How to repair names, see
# The most common case is to interleave two vectors vec_interleave(1:3, 4:6) #>  1 4 2 5 3 6 # But you aren't restricted to just two vec_interleave(1:3, 4:6, 7:9, 10:12) #>  1 4 7 10 2 5 8 11 3 6 9 12 # You can also interleave data frames x <- data_frame(x = 1:2, y = c("a", "b")) y <- data_frame(x = 3:4, y = c("c", "d")) vec_interleave(x, y) #> # A tibble: 4 × 2 #> x y #> <int> <chr> #> 1 1 a #> 2 3 c #> 3 2 b #> 4 4 d