Skip to content

Commit

Permalink
bind_rows() correctly handles consecutive NULLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Mar 22, 2019
1 parent d9794ec commit 8bbc2cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

* `group_map()` now only calls the function on each group and return a list.

* `bind_rows()` correctly handles the cases where there are multiple consecutive `NULL` (#4296).

# dplyr 0.8.0.1 (2019-02-15)

* Fixed integer C/C++ division, forced released by CRAN (#4185).
Expand Down
4 changes: 2 additions & 2 deletions src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Rcpp::List rbind__impl(Rcpp::List dots, const dplyr::SymbolString& id) {
SEXP* p_dots_names = STRING_PTR(dots_names);
SEXP* p_dots = get_vector_ptr(dots);

// we id_col now, so it is definitely younger than dots_names
// we create id_col now, so it is definitely younger than dots_names
// this is surely write barrier proof
SEXP id_col = PROTECT(Rf_allocVector(STRSXP, n));

Expand All @@ -273,7 +273,7 @@ Rcpp::List rbind__impl(Rcpp::List dots, const dplyr::SymbolString& id) {

// skip NULL on dots. because the way df_nrows is made above
// need to skip dots_names too
if (Rf_isNull(*p_dots)) {
while (Rf_isNull(*p_dots)) {
++p_dots;
++p_dots_names;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-rbind.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,16 @@ test_that("bind_rows warns on binding factor and character (#1485)", {
df2 <- tail(iris, 1) %>% mutate(Species = as.character(Species))
expect_warning(bind_rows(df1, df2), "binding factor and character vector, coercing into character vector")
})

test_that("bind_rows() correctly handles consecutive NULLs (#4296)", {
res <- list(
a = tibble(expected_id = "a"),
b = NULL,
c = NULL,
d = tibble(expected_id = "d"),
c = NULL,
e = tibble(expected_id = "e")
) %>%
bind_rows(.id = "id")
expect_equal(res$id, res$expected_id)
})

0 comments on commit 8bbc2cc

Please sign in to comment.