Skip to content

Commit

Permalink
Merge pull request #452 from tidyverse/group-by-non-standard-cols
Browse files Browse the repository at this point in the history
Allow grouping by non-standard column names
  • Loading branch information
markfairbanks authored Sep 19, 2023
2 parents 5328227 + 545a30a commit 7cd08da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

* Arguments to `$` and `[[` calls are no longer prepended with `..` (#434)

* Grouping now works with non-standard column names (#451)

# dtplyr 1.3.1

* Fix for failing R CMD check.
Expand Down
2 changes: 1 addition & 1 deletion R/step-group.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ group_by.dtplyr_step <- function(.data, ..., .add = FALSE, arrange = TRUE) {
groups <- eval(expr(dplyr::group_by_prepare(.data, !!!dots, .add = .add)))
arranged <- if (!is.null(.data$arrange)) .data$arrange && arrange else arrange

step_group(groups$data, as.character(groups$groups), arranged)
step_group(groups$data, as.character(groups$group_names), arranged)
}

can_step_group_return_early <- function(parent, groups, arrange) {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-step-group.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ test_that("only adds step if necessary", {
expect_s3_class(out, "dtplyr_step_group")
expect_equal(group_vars(out), character())
})

test_that("works with non-standard column names, #451", {
dt <- lazy_dt(tibble(`a a` = "a"))
res <- dt %>%
group_by(`a a`) %>%
count() %>%
as_tibble()
expect_named(res, c("a a", "n"))
expect_equal(res$`a a`, "a")
})

0 comments on commit 7cd08da

Please sign in to comment.