Skip to content

Commit

Permalink
Merge pull request tidyverse#4100 from tidyverse/distinct_prepare
Browse files Browse the repository at this point in the history
export distinct_prepare() (previously known as distinct_vars
  • Loading branch information
romainfrancois authored Jan 11, 2019
2 parents e848d6c + 4374c00 commit d71c52b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export(distinct_)
export(distinct_all)
export(distinct_at)
export(distinct_if)
export(distinct_prepare)
export(do)
export(do_)
export(dr_dplyr)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
group_map(~ head(.x, 2L))
```

* `distinct_prepare()`, previously known as `distinct_vars()` is exported. This is mostly useful for
alternative backends (e.g. `dbplyr`).

## Major changes

* `group_by()` respects levels of factors and keeps empty groups (#341).
Expand Down
2 changes: 1 addition & 1 deletion R/dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ reconstruct_set <- function(out, x) {

#' @export
distinct.data.frame <- function(.data, ..., .keep_all = FALSE) {
dist <- distinct_vars(.data, quos(...), .keep_all = .keep_all)
dist <- distinct_prepare(.data, quos(...), .keep_all = .keep_all)
vars <- match_vars(dist$vars, dist$data)
keep <- match_vars(dist$keep, dist$data)
distinct_impl(dist$data, vars, keep, environment())
Expand Down
7 changes: 4 additions & 3 deletions R/distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ distinct_ <- function(.data, ..., .dots, .keep_all = FALSE) {
UseMethod("distinct_")
}

#' Same basic philosophy as group_by: lazy_dots comes in, list of data and
#' Same basic philosophy as group_by_prepare(): lazy_dots comes in, list of data and
#' vars (character vector) comes out.
#' @noRd
distinct_vars <- function(.data, vars, group_vars = character(), .keep_all = FALSE) {
#' @rdname group_by_prepare
#' @export
distinct_prepare <- function(.data, vars, group_vars = character(), .keep_all = FALSE) {
stopifnot(is_quosures(vars), is.character(group_vars))

# If no input, keep all variables
Expand Down
6 changes: 3 additions & 3 deletions R/group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ ungroup <- function(x, ...) {

#' Prepare for grouping.
#'
#' Performs standard operations that should happen before individual methods
#' process the data. This includes mutating the tbl to add new grouping columns
#' and updating the groups (based on add)
#' `*_prepare()` performs standard manipulation that is needed prior
#' to actual data processing. They are only be needed by packages
#' that implement dplyr backends.
#'
#' @return A list
#' \item{data}{Modified tbl}
Expand Down
2 changes: 1 addition & 1 deletion R/grouped-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ do_.grouped_df <- function(.data, ..., env = caller_env(), .dots = list()) {

#' @export
distinct.grouped_df <- function(.data, ..., .keep_all = FALSE) {
dist <- distinct_vars(
dist <- distinct_prepare(
.data,
vars = quos(...),
group_vars = group_vars(.data),
Expand Down
17 changes: 11 additions & 6 deletions man/group_by_prepare.Rd

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

0 comments on commit d71c52b

Please sign in to comment.