Skip to content

Commit

Permalink
Fix data frame initialisation in bind_rows()
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Apr 19, 2021
1 parent 8b036bc commit 43b5eea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
* `mutate()` always keeps grouping variables, unconditional to `.keep=` (#5582).

* dplyr now depends on R 3.3.0
* Fixed issue in `bind_rows()` causing lists to be incorrectly transformed as
data frames (#5417).


# dplyr 1.0.2

Expand Down
2 changes: 1 addition & 1 deletion R/bind.r
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bind_rows <- function(..., .id = NULL) {
first <- dots[[1L]]
dots <- map(dots, function(.x) {
if (vec_is_list(.x)) {
.x <- new_data_frame(as.list(.x))
.x <- vctrs::data_frame(!!!.x)
}
.x
})
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-bind.R
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,18 @@ test_that("bind_rows() correctly restores (#2457)", {
expect_s3_class(df$x, "vctrs_list_of")
})

test_that("bind_rows() validates lists (#5417)", {
out <- bind_rows(list(x = 1), list(x = 1, y = 1:2))
expect_identical(out, tibble(x = c(1, 1, 1), y = c(NA, 1:2)))

x <- vctrs::list_of(a = data.frame(x = 1), b = data.frame(y = 2:3))
out <- bind_rows(x)
exp <- tibble(
a = vctrs::data_frame(x = c(1, 1), y = int(NA, NA)),
b = vctrs::data_frame(x = dbl(NA, NA), y = 2:3)
)
expect_identical(out, exp)
})

# Errors ------------------------------------------------------------------

Expand Down

0 comments on commit 43b5eea

Please sign in to comment.