1
votes

I want to create the following tibble by starting with an empty tibble

expected = tibble::tibble(z = 1:10, w = 2:11)

However, the following code doesn't work and shows the error.

actual= tibble::tibble()
actual = dplyr::bind_cols(actual, tibble::tibble(z = 1:10))
actual = dplyr::bind_cols(actual, tibble::tibble(w = 2:11))

Error: Can't recycle `..1` (size 0) to match `..2` (size 10).

The version of dplyr is 1.0.0 and that of tibble is 3.0.1. This code has no problem in dplyr old version 0.8.3


Thanks for your comments. Sorry for my insufficient explanation. To be accurate, I want to use only dplyr::bind_cols in iteration.

actual= tibble::tibble()
tibbles = list(tibble::tibble(z = 1:10),
               tibble::tibble(w = 2:11))     
for(i in 1:length(tibbles)){
   actual = dplyr::bind_cols(actual, tibbles[[i]])
}
1
I get Error: Argument 2 must be length 0, not 10 in dplyr 0.8.3 and the same error message as you on dplyr 1.0.0. - Ronak Shah

1 Answers

1
votes

You want bind_rows() not bind_cols() in your first update:

actual= tibble::tibble()
actual = dplyr::bind_rows(actual, tibble::tibble(z = 1:10))
actual = dplyr::bind_cols(actual, tibble::tibble(w = 2:11))
actual
# A tibble: 10 x 2
       z     w
   <int> <int>
 1     1     2
 2     2     3
 3     3     4
 4     4     5
 5     5     6
 6     6     7
 7     7     8
 8     8     9
 9     9    10
10    10    11