eitsupi commented on code in PR #14122:
URL: https://github.com/apache/arrow/pull/14122#discussion_r971813051
##########
r/R/dplyr-group-by.R:
##########
@@ -24,34 +24,25 @@ group_by.arrow_dplyr_query <- function(.data,
add = .add,
.drop =
dplyr::group_by_drop_default(.data)) {
.data <- as_adq(.data)
- new_groups <- enquos(...)
- # ... can contain expressions (i.e. can add (or rename?) columns) and so we
- # need to identify those and add them on to the query with mutate.
Specifically,
- # we want to mark as new:
- # * expressions (named or otherwise)
- # * variables that have new names
- # All others (i.e. simple references to variables) should not be (re)-added
+ expression_list <- expand_across(.data, quos(...))
+ new_groups <- ensure_named_exprs(expression_list)
- # Identify any groups with names which aren't in names of .data
- new_group_ind <- map_lgl(new_groups, ~ !(quo_name(.x) %in% names(.data)))
- # Identify any groups which don't have names
- named_group_ind <- map_lgl(names(new_groups), nzchar)
- # Retain any new groups identified above
- new_groups <- new_groups[new_group_ind | named_group_ind]
if (length(new_groups)) {
- # now either use the name that was given in ... or if that is "" then use
the expr
- names(new_groups) <- imap_chr(new_groups, ~ ifelse(.y == "", quo_name(.x),
.y))
-
# Add them to the data
.data <- dplyr::mutate(.data, !!!new_groups)
}
- if (".add" %in% names(formals(dplyr::group_by))) {
- # For compatibility with dplyr >= 1.0
- gv <- dplyr::group_by_prepare(.data, ..., .add = .add)$group_names
+
+ if (!".add" %in% names(formals(dplyr::group_by))) {
+ # For compatibility with dplyr < 1.0
+ .add <- add
+ }
Review Comment:
It appears that it needs to be modified to behave similarly to how dplyr
behaves.
``` r
mtcars |> dplyr::group_by(add = cyl)
#> Warning: The `add` argument of `group_by()` is deprecated as of dplyr
1.0.0.
#> Please use the `.add` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
generated.
#> Error in group_by_prepare(.data, ..., .add = .add, caller_env =
caller_env()): object 'cyl' not found
```
<sup>Created on 2022-09-15 with [reprex
v2.0.2](https://reprex.tidyverse.org)</sup>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]