Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow grouping by non-standard column names #452

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
})
Loading