Here is a code snippet:
y <- purrr::map(1:2, ~ c(a=.x))
test1 <- dplyr::bind_rows(y)
test2 <- do.call(dplyr::bind_rows, y)
The fir
From the documentation of bind_rows
:
Note that for historical reasons, lists containg vectors are always treated as data frames. Thus their vectors are treated as columns rather than rows, and their inner names are ignored
Here, your y
as constructed has only inner names - it is two unnamed list elements, each containing a length-one vector with the vector element named a
. So this error seems to be expected.
If you name the list elements, you can see that it behaves as described, with the vectors treated as columns:
library(tidyverse)
y <- map(1:2, ~ c(a=.x)) %>%
set_names(c("a", "b"))
bind_rows(y)
#> # A tibble: 1 x 2
#> a b
#> <int> <int>
#> 1 1 2
The difference with supplying y
as arguments via do.call
is that it's more like writing bind_rows(c(a = 1), c(a = 2))
. This is not a list containing vectors, but separate vectors, so it binds by row as expected.