diff --git a/NEWS.md b/NEWS.md index 5c4d9d76..320ba271 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/step-group.R b/R/step-group.R index 98c5b579..511ca6ad 100644 --- a/R/step-group.R +++ b/R/step-group.R @@ -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) { diff --git a/tests/testthat/test-step-group.R b/tests/testthat/test-step-group.R index 959ccf05..07610827 100644 --- a/tests/testthat/test-step-group.R +++ b/tests/testthat/test-step-group.R @@ -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") +})