Skip to content

Commit dfc9ab1

Browse files
authored
Unify and improve on ... warning with group functions (#7753)
1 parent 6493816 commit dfc9ab1

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

R/group-nest.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,18 @@ group_nest.data.frame <- function(.tbl, ..., .key = "data", keep = FALSE) {
6868
#' @export
6969
group_nest.grouped_df <- function(.tbl, ..., .key = "data", keep = FALSE) {
7070
if (dots_n(...)) {
71-
warn(
72-
"... is ignored in group_nest(<grouped_df>), please use group_by(..., .add = TRUE) |> group_nest()"
71+
warn_ignores_dots(
72+
"group_nest",
73+
"grouped_df",
74+
"group_by(..., .add = TRUE) |> group_nest()"
7375
)
7476
}
7577
group_nest_impl(.tbl, .key = .key, keep = keep)
7678
}
79+
80+
# This is not a deprecation warning, just giving advice
81+
warn_ignores_dots <- function(fn, class, with) {
82+
cli::cli_warn(
83+
"Calling {.fn {fn}} on a {.cls {class}} ignores `...`. Please use {.code {with}}."
84+
)
85+
}

R/group-split.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ group_split.rowwise_df <- function(
7474
keep = deprecated()
7575
) {
7676
if (dots_n(...)) {
77-
warn(
78-
"... is ignored in group_split(<rowwise_df>), please use as_tibble() |> group_split(...)"
77+
warn_ignores_dots(
78+
"group_split",
79+
"rowwise_df",
80+
"as_tibble() |> group_split(...)"
7981
)
8082
}
8183
if (!missing(keep)) {
@@ -111,8 +113,10 @@ group_split.grouped_df <- function(
111113
.keep <- keep
112114
}
113115
if (dots_n(...)) {
114-
warn(
115-
"... is ignored in group_split(<grouped_df>), please use group_by(..., .add = TRUE) |> group_split()"
116+
warn_ignores_dots(
117+
"group_split",
118+
"grouped_df",
119+
"group_by(..., .add = TRUE) |> group_split()"
116120
)
117121
}
118122

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# group_nest.grouped_df() warns about `...`
2+
3+
Code
4+
group_nest(group_by(mtcars, cyl), cyl)
5+
Condition
6+
Warning:
7+
Calling `group_nest()` on a <grouped_df> ignores `...`. Please use `group_by(..., .add = TRUE) |> group_nest()`.
8+
Output
9+
# A tibble: 3 x 2
10+
cyl data
11+
<dbl> <list<tibble[,10]>>
12+
1 4 [11 x 10]
13+
2 6 [7 x 10]
14+
3 8 [14 x 10]
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# group_split.grouped_df() warns about `...`
2+
3+
Code
4+
out <- group_split(group_by(mtcars, cyl), cyl)
5+
Condition
6+
Warning:
7+
Calling `group_split()` on a <grouped_df> ignores `...`. Please use `group_by(..., .add = TRUE) |> group_split()`.
8+
9+
# group_split.rowwise_df() warns about `...`
10+
11+
Code
12+
out <- group_split(rowwise(mtcars), cyl)
13+
Condition
14+
Warning:
15+
Calling `group_split()` on a <rowwise_df> ignores `...`. Please use `as_tibble() |> group_split(...)`.
16+

tests/testthat/test-group-nest.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ test_that("group_nest() works on grouped data frames", {
4747
expect_equal(names(bind_rows(!!!res$data)), names(starwars))
4848
})
4949

50-
test_that("group_nest.grouped_df() warns about ...", {
51-
expect_warning(group_nest(group_by(mtcars, cyl), cyl))
50+
test_that("group_nest.grouped_df() warns about `...`", {
51+
expect_snapshot({
52+
group_nest(group_by(mtcars, cyl), cyl)
53+
})
5254
})
5355

5456
test_that("group_nest() works if no grouping column", {

tests/testthat/test-group-split.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ test_that("group_split() respects empty groups", {
4141
expect_identical(res, list_of(tbl[1:2, ], tbl[3:4, ], tbl[integer(), ]))
4242
})
4343

44-
test_that("group_split.grouped_df() warns about ...", {
45-
expect_warning(group_split(group_by(mtcars, cyl), cyl))
44+
test_that("group_split.grouped_df() warns about `...`", {
45+
expect_snapshot({
46+
out <- group_split(group_by(mtcars, cyl), cyl)
47+
})
4648
})
4749

48-
test_that("group_split.rowwise_df() warns about ...", {
49-
expect_warning(group_split(rowwise(mtcars), cyl))
50+
test_that("group_split.rowwise_df() warns about `...`", {
51+
expect_snapshot({
52+
out <- group_split(rowwise(mtcars), cyl)
53+
})
5054
})
5155

5256
test_that("group_split.grouped_df() works", {

0 commit comments

Comments
 (0)