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

Don't allow renaming in group_by() #800

Merged
merged 4 commits into from
Feb 12, 2024
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
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
Loading