`bind_cols()` should recycle a 1-row df #3170
Closed
Labels
Comments
Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session. (Also, no need for a session info unless it's asked for) |
Adding a (slightly more minimal) reprex based on OP: library(dplyr)
one <- as_tibble(head(iris, 3))
two <- tibble(x1 = 1, x2 = 2)
# For this operation:
as_tibble(cbind(one, two))
#> # A tibble: 3 x 7
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species x1 x2
#> * <dbl> <dbl> <dbl> <dbl> <fctr> <dbl> <dbl>
#> 1 5.1 3.5 1.4 0.2 setosa 1 2
#> 2 4.9 3.0 1.4 0.2 setosa 1 2
#> 3 4.7 3.2 1.3 0.2 setosa 1 2
# we would expect this to work too:
bind_cols(one, two)
#> Error in cbind_all(x): Argument 2 must be length 1, not 3 |
Thanks. I'm not sure we want this, because this would add a lot of complexity to the implementation, and allow for mistakes. You can already use library(tibble)
library(magrittr)
to_add <- tibble(a = 1, b = 2)
mtcars[1:2] %>% add_column(!!! to_add) %>% head()
#> mpg cyl a b
#> Mazda RX4 21.0 6 1 2
#> Mazda RX4 Wag 21.0 6 1 2
#> Datsun 710 22.8 4 1 2
#> Hornet 4 Drive 21.4 6 1 2
#> Hornet Sportabout 18.7 8 1 2
#> Valiant 18.1 6 1 2
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: