diff --git a/NAMESPACE b/NAMESPACE index 40f4c68..5a091e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,6 +59,7 @@ export(transmute) export(transmute_all) export(transmute_at) export(transmute_if) +export(uncount) export(ungroup) import(clisymbols) import(dplyr) diff --git a/NEWS.md b/NEWS.md index 31c3783..c0e2c14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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) diff --git a/R/summarize.R b/R/summarize.R index f0eb4a3..2757ea0 100644 --- a/R/summarize.R +++ b/R/summarize.R @@ -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, ...) diff --git a/man/summarize.Rd b/man/summarize.Rd index b8cb45f..fede4ea 100644 --- a/man/summarize.Rd +++ b/man/summarize.Rd @@ -11,6 +11,7 @@ \alias{summarise_if} \alias{tally} \alias{count} +\alias{uncount} \title{Wrapper around dplyr::summarize and related functions that prints information about the operation} \usage{ @@ -33,6 +34,8 @@ summarise_if(.data, ...) tally(.data, ...) count(.data, ...) + +uncount(.data, ...) } \arguments{ \item{.data}{a tbl; see \link[dplyr]{summarize}} diff --git a/tests/testthat/test_summarize.R b/tests/testthat/test_summarize.R index 6420b09..81bc663 100644 --- a/tests/testthat/test_summarize.R +++ b/tests/testthat/test_summarize.R @@ -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)