Skip to content

Commit

Permalink
Force comma separated group labels at all times (#7661)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan authored Feb 19, 2025
1 parent fb25640 commit 49fb23a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cur_group_rows <- function() {
group_labels_details <- function(keys) {
keys <- map_chr(keys, pillar::format_glimpse)
labels <- vec_paste0(names(keys), " = ", keys)
labels <- cli_collapse(labels, last = ", ")
labels <- cli_collapse(labels, last = ", ", sep2 = ", ")
cli::format_inline("{.code {labels}}")
}

Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ node_walk_replace <- function(node, old, new) {
}
}

cli_collapse <- function(x, last = " and ") {
cli::cli_vec(x, style = list("vec-last" = last))
cli_collapse <- function(x, last = " and ", sep2 = " and ") {
cli::cli_vec(x, style = list("vec-last" = last, "vec-sep2" = sep2))
}

with_no_rlang_infix_labeling <- function(expr) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
Code
group_labels_details(c(a = 1, b = 2))
Output
[1] "`a = 1` and `b = 2`"
[1] "`a = 1`, `b = 2`"

12 changes: 11 additions & 1 deletion tests/testthat/_snaps/summarise.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@
<error/rlang_error>
Error in `summarise()`:
i In argument: `a = rlang::env(a = 1)`.
i In group 1: `x = 1` and `y = 1`.
i In group 1: `x = 1`, `y = 1`.
Caused by error:
! `a` must be a vector, not an environment.
Code
(expect_error(tibble(x = 1, y = c(1, 2, 2), y2 = c(1, 2, 2), z = runif(3)) %>%
group_by(x, y, y2) %>% summarise(a = rlang::env(a = 1))))
Output
<error/rlang_error>
Error in `summarise()`:
i In argument: `a = rlang::env(a = 1)`.
i In group 1: `x = 1`, `y = 1`, `y2 = 1`.
Caused by error:
! `a` must be a vector, not an environment.
Code
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-summarise.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ test_that("summarise() gives meaningful errors", {
group_by(x, y) %>%
summarise(a = rlang::env(a = 1))
))
(expect_error(
tibble(x = 1, y = c(1, 2, 2), y2 = c(1, 2, 2), z = runif(3)) %>%
group_by(x, y, y2) %>%
summarise(a = rlang::env(a = 1))
))
(expect_error(
tibble(x = 1, y = c(1, 2, 2), z = runif(3)) %>%
rowwise() %>%
Expand Down

0 comments on commit 49fb23a

Please sign in to comment.