From da8805c34c605835d4d54e93381a755f4114b1a5 Mon Sep 17 00:00:00 2001 From: eutwt <11261404+eutwt@users.noreply.github.com> Date: Sun, 22 Aug 2021 13:28:44 -0400 Subject: [PATCH 1/5] desc() checks the number of arguments. --- R/tidyeval.R | 3 +++ tests/testthat/_snaps/tidyeval.md | 7 +++++++ tests/testthat/test-tidyeval.R | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/R/tidyeval.R b/R/tidyeval.R index b1292757f..88de0b2c7 100644 --- a/R/tidyeval.R +++ b/R/tidyeval.R @@ -130,6 +130,9 @@ dt_squash_call <- function(x, env, data, j = TRUE) { } else if (is_call(x, "cur_group_rows")) { quote(.I) } else if (is_call(x, "desc")) { + if (!has_length(x, 2L)) { + abort("`desc()` expects exactly one argument.") + } x[[1]] <- sym("-") x[[2]] <- get_expr(x[[2]]) x diff --git a/tests/testthat/_snaps/tidyeval.md b/tests/testthat/_snaps/tidyeval.md index 10eea667c..7049ca42d 100644 --- a/tests/testthat/_snaps/tidyeval.md +++ b/tests/testthat/_snaps/tidyeval.md @@ -2,3 +2,10 @@ The `order_by` argument of `lag()` is not supported by dtplyr +# desc() checks the number of arguments + + Code + capture_dots(df, desc(a, b)) + Error + `desc()` expects exactly one argument. + diff --git a/tests/testthat/test-tidyeval.R b/tests/testthat/test-tidyeval.R index 258a55e8a..f93bdc0ca 100644 --- a/tests/testthat/test-tidyeval.R +++ b/tests/testthat/test-tidyeval.R @@ -262,6 +262,10 @@ test_that("`desc(col)` is translated to `-col` inside arrange", { expect_equal(out$x, c("b", "a")) }) +test_that("desc() checks the number of arguments", { + expect_snapshot(error = TRUE, capture_dots(df, desc(a, b))) +}) + test_that("n_distinct() is translated to uniqueN()", { # Works with multiple inputs expect_equal( From 663ed9f3304c4cdfb73e9953e1b87dc6a71350dc Mon Sep 17 00:00:00 2001 From: eutwt <11261404+eutwt@users.noreply.github.com> Date: Sun, 22 Aug 2021 13:36:43 -0400 Subject: [PATCH 2/5] s/dots/dot/ --- tests/testthat/test-tidyeval.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-tidyeval.R b/tests/testthat/test-tidyeval.R index f93bdc0ca..04df5c390 100644 --- a/tests/testthat/test-tidyeval.R +++ b/tests/testthat/test-tidyeval.R @@ -263,7 +263,7 @@ test_that("`desc(col)` is translated to `-col` inside arrange", { }) test_that("desc() checks the number of arguments", { - expect_snapshot(error = TRUE, capture_dots(df, desc(a, b))) + expect_snapshot(error = TRUE, capture_dot(df, desc(a, b))) }) test_that("n_distinct() is translated to uniqueN()", { From 3737f63dcbfe8c562e67e7b74165275608c9ae92 Mon Sep 17 00:00:00 2001 From: eutwt <11261404+eutwt@users.noreply.github.com> Date: Sun, 22 Aug 2021 13:37:23 -0400 Subject: [PATCH 3/5] update snapshot --- tests/testthat/_snaps/tidyeval.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/tidyeval.md b/tests/testthat/_snaps/tidyeval.md index 7049ca42d..ee21cf65a 100644 --- a/tests/testthat/_snaps/tidyeval.md +++ b/tests/testthat/_snaps/tidyeval.md @@ -5,7 +5,7 @@ # desc() checks the number of arguments Code - capture_dots(df, desc(a, b)) + capture_dot(df, desc(a, b)) Error `desc()` expects exactly one argument. From 3cf592bd5c80ceb17df5a9e6c04a3a6afa66c98c Mon Sep 17 00:00:00 2001 From: eutwt <11261404+eutwt@users.noreply.github.com> Date: Tue, 7 Sep 2021 08:42:46 -0400 Subject: [PATCH 4/5] add news --- NEWS.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index fa3cab92e..2c537bc4b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,6 @@ # dtplyr (development version) -* `tally()` and `count()` now follow the dplyr convention of creating a unique - name if the default output `name` (n) already exists (@eutwt, #295). - -* Fixed a bug which prevented changing the value of a group variable with - `summarise()`, `tally()`, or `count()` (@eutwt, #295). +* `desc()` now gives an error if more than one argument is provided (@eutwt #285). * `if_any()` and `if_all()` now default to `.cols = everything()` when `.cols` isn't provided (@eutwt, #294). From c7d67c89977e0fef2b2029e9a80bd5fb62fb7963 Mon Sep 17 00:00:00 2001 From: eutwt <11261404+eutwt@users.noreply.github.com> Date: Tue, 7 Sep 2021 09:04:39 -0400 Subject: [PATCH 5/5] Revert "add news" This reverts commit 3cf592bd5c80ceb17df5a9e6c04a3a6afa66c98c. --- NEWS.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2c537bc4b..fa3cab92e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ # dtplyr (development version) -* `desc()` now gives an error if more than one argument is provided (@eutwt #285). +* `tally()` and `count()` now follow the dplyr convention of creating a unique + name if the default output `name` (n) already exists (@eutwt, #295). + +* Fixed a bug which prevented changing the value of a group variable with + `summarise()`, `tally()`, or `count()` (@eutwt, #295). * `if_any()` and `if_all()` now default to `.cols = everything()` when `.cols` isn't provided (@eutwt, #294).