Skip to content

Commit

Permalink
Superseded with_groups()
Browse files Browse the repository at this point in the history
Fixes #6582
  • Loading branch information
hadley committed Dec 15, 2022
1 parent 3b696db commit be75883
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dplyr (development version)

* `with_groups()` is superseded in favour of `.by` (#6582)

* `slice()` with no inputs now returns 0 rows. This is mostly for theoretical
consistency (#6573).

Expand Down
23 changes: 9 additions & 14 deletions R/groups-with.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#' Perform an operation with temporary groups
#'
#' @description
#' `r lifecycle::badge("experimental")`
#' `r lifecycle::badge("superseded")`
#'
#' This is an experimental new function that allows you to modify the grouping
#' variables for a single operation.
#' This was an experimental function that allows you to modify the grouping
#' variables for a single operation; it is superseded in favour of using the
#' `.by` argument to individual verbs.
#'
#' @param .data A data frame
#' @param .groups <[`tidy-select`][dplyr_tidy_select]> One or more variables
Expand All @@ -16,22 +17,16 @@
#' @param .f Function to apply to regrouped data.
#' Supports purrr-style `~` syntax
#' @param ... Additional arguments passed on to `...`.
#' @keywords internal
#' @export
#' @examples
#' df <- tibble(g = c(1, 1, 2, 2, 3), x = runif(5))
#' df %>%
#' with_groups(g, mutate, x_mean = mean(x))
#' df %>%
#' with_groups(g, ~ mutate(.x, x1 = first(x)))
#'
#' # Old
#' df %>%
#' group_by(g) %>%
#' with_groups(NULL, mutate, x_mean = mean(x))
#'
#' # NB: grouping can't be restored if you remove the grouping variables
#' df %>%
#' group_by(g) %>%
#' with_groups(NULL, mutate, g = NULL)
#' with_groups(g, mutate, x_mean = mean(x))
#' # New
#' df %>% mutate(x_mean = mean(x), .by = g)
with_groups <- function(.data, .groups, .f, ...) {
lifecycle::signal_stage("experimental", "with_groups()")
loc <- tidyselect::eval_select(enquo(.groups), data = tbl_ptype(.data))
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ reference:
- group_modify
- group_trim
- group_split
- with_groups

- title: Superseded
desc: >
Expand All @@ -123,6 +122,7 @@ reference:
- ends_with("_at")
- all_vars
- vars
- with_groups

- title: Remote tables
contents:
Expand Down
23 changes: 9 additions & 14 deletions man/with_groups.Rd

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

0 comments on commit be75883

Please sign in to comment.