Skip to content

Commit

Permalink
Respect grouping in fill(). Fixes #129
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Dec 30, 2015
1 parent cdc0baf commit 849aab5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# tidyr 0.3.1.9000

* `fill()` respects grouping from `group_by()` (#129).

* `fill()` fills in `NULL`s in list-columns.

* `fill()` gains a direction argument so that it can fill either upwards or
Expand Down
5 changes: 5 additions & 0 deletions R/fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up")) {

data
}

#' @export
fill_.grouped_df <- function(data, fill_cols, .direction = c("down", "up")) {
do(data, fill_(., fill_cols = fill_cols, .direction = .direction))
}
6 changes: 6 additions & 0 deletions tests/testthat/test-fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ test_that("fill preserves attributes", {
expect_equal(attributes(out_d$x), attributes(df$x))
expect_equal(attributes(out_u$x), attributes(df$x))
})

test_that("fill respects grouping", {
df <- dplyr::data_frame(x = c(1, 1, 2), y = c(1, NA, NA))
out <- df %>% dplyr::group_by(x) %>% fill(y)
expect_equal(out$y, c(1, 1, NA))
})

0 comments on commit 849aab5

Please sign in to comment.