Skip to content

Commit

Permalink
add support for uncount
Browse files Browse the repository at this point in the history
  • Loading branch information
elbersb committed Jan 6, 2020
1 parent 6dadd44 commit d81327e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export(transmute)
export(transmute_all)
export(transmute_at)
export(transmute_if)
export(uncount)
export(ungroup)
import(clisymbols)
import(dplyr)
Expand Down
9 changes: 5 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# 0.2.0.9000

- support for pivot_longer, pivot_wider
- support for ungroup (thanks @damianooldoni)
- support for rename_* (#27)
- support for top_frac, sample_n, sample_frac, slice
- tidyr: support for pivot_longer, pivot_wider
- dplyr: support for ungroup (thanks @damianooldoni)
- dplyr: support for rename_* (#27)
- dplyr: support for top_frac, sample_n, sample_frac, slice
- tidyr: support for uncount

# 0.2.0
- added detailed merge information for joins (#25)
Expand Down
6 changes: 6 additions & 0 deletions R/summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ count <- function(.data, ...) {
log_summarize(.data, .fun = dplyr::count, .funname = "count", ...)
}

#' @rdname summarize
#' @export
uncount <- function(.data, ...) {
log_summarize(.data, .fun = tidyr::uncount, .funname = "uncount", ...)
}

log_summarize <- function(.data, .fun, .funname, ...) {
newdata <- .fun(.data, ...)

Expand Down
3 changes: 3 additions & 0 deletions man/summarize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test_summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ test_that("count", {
expect_equal(ncol(out), 3)
})

test_that("uncount", {
expect_message({
df <- tibble(x = c("a", "b"), n = c(1, 2))
out <- uncount(df, n)
})
expect_equal(nrow(out), 3)
expect_equal(ncol(out), 1)
})

test_that("summarize: scoped variants", {
expect_message({
out <- tidylog::summarize_all(mtcars, max)
Expand Down

0 comments on commit d81327e

Please sign in to comment.