Skip to content

Commit

Permalink
Better arg name for group_by.
Browse files Browse the repository at this point in the history
Closes #534
  • Loading branch information
hadley committed Aug 27, 2014
1 parent b431d30 commit 20768a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dplyr 0.2.0.99

* Change first argument name of `group_by()` to `.data` so you can create
new groups with name x (#534).

* The `Progress` refclass is no longer exported to avoid conflicts with shiny.
Instead use `progress_estimated()` (#535).

Expand Down
12 changes: 6 additions & 6 deletions R/group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@
#'
#' # Duplicate groups are silently dropped
#' groups(group_by(by_cyl, cyl, cyl))
group_by <- function(x, ..., add = FALSE) {
group_by <- function(.data, ..., add = FALSE) {
new_groups <- named_dots(...)

# If any calls, use mutate to add new columns, then group by those
calls <- vapply(new_groups, function(x) !is.name(x), logical(1))
if (any(calls)) {
env <- new.env(parent = parent.frame())
env$x <- x
env$.data <- .data

call <- as.call(c(quote(mutate), quote(x), new_groups[calls]))
x <- eval(call, env)
call <- as.call(c(quote(mutate), quote(.data), new_groups[calls]))
.data <- eval(call, env)

new_groups[calls] <- lapply(names(new_groups)[calls], as.name)
}
names(new_groups) <- NULL

if (add) {
new_groups <- c(groups(x), new_groups)
new_groups <- c(groups(.data), new_groups)
}
new_groups <- new_groups[!duplicated(new_groups)]

regroup(x, new_groups)
regroup(.data, new_groups)
}

#' Get/set the grouping variables for tbl.
Expand Down
2 changes: 1 addition & 1 deletion man/group_by.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\alias{group_by}
\title{Group a tbl by one or more variables.}
\usage{
group_by(x, ..., add = FALSE)
group_by(.data, ..., add = FALSE)
}
\arguments{
\item{x}{a tbl}
Expand Down

0 comments on commit 20768a5

Please sign in to comment.