Skip to content

Commit

Permalink
Merge pull request #800 from markfairbanks/group_by-no-rename
Browse files Browse the repository at this point in the history
Don't allow renaming in `group_by()`
  • Loading branch information
markfairbanks authored Feb 12, 2024
2 parents 1def52c + 7e66ec0 commit 7c51151
Show file tree
Hide file tree
Showing 4 changed files with 20 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 @@
# tidytable 0.11.1 (in development)

#### Bug fixes
* Attempting to rename columns using `group_by()` now leads to an error (#799)

# tidytable 0.11.0

#### Functionality improvements
Expand Down
2 changes: 1 addition & 1 deletion R/group_by.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ group_by <- function(.df, ..., .add = FALSE) {
group_by.tidytable <- function(.df, ..., .add = FALSE) {
dots <- enquos(...)
check_no_across(dots)
.groups <- tidyselect_names(.df, !!!dots)
.groups <- tidyselect_names(.df, !!!dots, .allow_rename = FALSE)
if (length(.groups) == 0) {
out <- .df
} else {
Expand Down
12 changes: 6 additions & 6 deletions R/utils-tidyselect.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# _names: Get column names (as a character vector)
# _syms: Get column names (as a list of symbols)

tidyselect_locs <- function(.df, ...) {
eval_select(expr(c(...)), .df)
tidyselect_locs <- function(.df, ..., .allow_rename = TRUE) {
eval_select(expr(c(...)), .df, allow_rename = .allow_rename)
}

tidyselect_names <- function(.df, ...) {
names(tidyselect_locs(.df, ...))
tidyselect_names <- function(.df, ..., .allow_rename = TRUE) {
names(tidyselect_locs(.df, ..., .allow_rename = .allow_rename))
}

tidyselect_syms <- function(.df, ...) {
syms(tidyselect_names(.df, ...))
tidyselect_syms <- function(.df, ..., .allow_rename = TRUE) {
syms(tidyselect_names(.df, ..., .allow_rename = .allow_rename))
}
10 changes: 10 additions & 0 deletions tests/testthat/test-group_by.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ test_that("group_by works with .add", {
expect_true(is_grouped_df(res))
})

test_that("group_by errors on rename, #799", {
df <- tidytable(x = c("a", "a", "b"),
y = 1:3)
expect_error(
group_by(df, new_x = x)
)
})

##### ungroup() -------------------------------------------

test_that("works on rowwise_tt", {
df <- rowwise(tidytable(x = 1:3, y = 1:3))
res <- ungroup(df)
Expand Down

0 comments on commit 7c51151

Please sign in to comment.