From bf2ac30f37d4804d3a22aa82345c65832a97a22f Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 16 Aug 2022 09:55:27 -0500 Subject: [PATCH 1/5] Deprecate .data Fixes #169 --- NEWS.md | 4 ++++ R/eval-walk.R | 5 +++++ tests/testthat/_snaps/eval-walk.md | 9 +++++++++ tests/testthat/test-eval-walk.R | 9 +++++++++ tests/testthat/test-lifecycle-deprecated.R | 2 ++ 5 files changed, 29 insertions(+) diff --git a/NEWS.md b/NEWS.md index fae102dc..e06eb3f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # tidyselect (development version) +* Use of `.data` in tidyselect expressions is now deprecated to more cleanly + separate tidy-select from data-masking. Use `any_of()` or `all_of()` instead + (#169). + * `peek_var()` error now generates hyperlink to docs with recent RStudio (#289). * `all_of()` (like `any_of()`) now fails when used outside of a diff --git a/R/eval-walk.R b/R/eval-walk.R index 37f34aeb..19ac94f6 100644 --- a/R/eval-walk.R +++ b/R/eval-walk.R @@ -271,6 +271,11 @@ call_kind <- function(expr, error_call) { fn <- as_string(head) if (fn %in% c("$", "[[") && identical(node_cadr(expr), quote(.data))) { + lifecycle::deprecate_warn("1.2.0", + what = I("Use of .data in tidyselect expressions"), + with = I("`any_of()` or `all_of()`") + ) + validate_dot_data(expr, error_call) return(".data") } diff --git a/tests/testthat/_snaps/eval-walk.md b/tests/testthat/_snaps/eval-walk.md index 4cb7a85e..bde9fb70 100644 --- a/tests/testthat/_snaps/eval-walk.md +++ b/tests/testthat/_snaps/eval-walk.md @@ -76,6 +76,15 @@ Caused by error: ! object 'foobar' not found +# use of .data is deprecated + + Code + x <- select_loc(x, .data$a) + Condition + Warning: + Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0. + Please use `any_of()` or `all_of()` instead. + # eval_walk() has informative messages Code diff --git a/tests/testthat/test-eval-walk.R b/tests/testthat/test-eval-walk.R index f04d469b..cdf9ad51 100644 --- a/tests/testthat/test-eval-walk.R +++ b/tests/testthat/test-eval-walk.R @@ -269,12 +269,19 @@ test_that("selections provide informative errors", { }) test_that("can select with .data pronoun (#2715)", { + withr::local_options(lifecycle_verbosity = "quiet") + expect_identical(select_loc(c(foo = "foo"), .data$foo), c(foo = 1L)) expect_identical(select_loc(c(foo = "foo"), .data[["foo"]]), c(foo = 1L)) expect_identical(select_loc(letters2, .data$a:.data$b), c(a = 1L, b = 2L)) expect_identical(select_loc(letters2, .data[["a"]]:.data[["b"]]), c(a = 1L, b = 2L)) }) +test_that("use of .data is deprecated", { + x <- list(a = 1, b = 2, c = 3) + expect_snapshot(x <- select_loc(x, .data$a)) +}) + test_that(".data in env-expression has the lexical definition", { quo <- local({ .data <- mtcars @@ -327,6 +334,8 @@ test_that("eval_sym() still supports predicate functions starting with `is`", { }) test_that("eval_walk() has informative messages", { + withr::local_options(lifecycle_verbosity = "quiet") + expect_snapshot({ "# Using a predicate without where() warns" invisible(select_loc(iris, is_integer)) diff --git a/tests/testthat/test-lifecycle-deprecated.R b/tests/testthat/test-lifecycle-deprecated.R index 0cdd5e63..e6833fa7 100644 --- a/tests/testthat/test-lifecycle-deprecated.R +++ b/tests/testthat/test-lifecycle-deprecated.R @@ -326,6 +326,8 @@ test_that("vars_rename() sets variable context", { }) test_that("vars_rename() supports `.data` pronoun", { + withr::local_options(lifecycle_verbosity = "quiet") + expect_identical(vars_rename(c("a", "b"), B = .data$b), c(a = "a", B = "b")) }) From 0012fe8d516d10590cddb05dce72d28de009aadd Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 17 Aug 2022 14:34:49 -0500 Subject: [PATCH 2/5] Use dev lifecycle --- DESCRIPTION | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 7b21f3ac..c754329d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,7 @@ Depends: Imports: cli (>= 3.3.0), glue (>= 1.3.0), + lifecycle (>= 1.0.1.9000), rlang (>= 1.0.4), vctrs (>= 0.4.1), withr @@ -39,3 +40,5 @@ Config/Needs/website: tidyverse/tidytemplate Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 +Remotes: + r-lib/lifecycle From 67ee98d2838453d71adf0b4b20e7cbe839715bb3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 17 Aug 2022 17:24:43 -0500 Subject: [PATCH 3/5] Update snapshots with latest tidyselect --- tests/testthat/_snaps/eval-walk.md | 1 + tests/testthat/_snaps/vars-pull.md | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/_snaps/eval-walk.md b/tests/testthat/_snaps/eval-walk.md index 8e916ea4..4471a7f2 100644 --- a/tests/testthat/_snaps/eval-walk.md +++ b/tests/testthat/_snaps/eval-walk.md @@ -84,6 +84,7 @@ Warning: Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0. Please use `any_of()` or `all_of()` instead. + Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. # eval_walk() has informative messages diff --git a/tests/testthat/_snaps/vars-pull.md b/tests/testthat/_snaps/vars-pull.md index bcf459ad..ed37f19a 100644 --- a/tests/testthat/_snaps/vars-pull.md +++ b/tests/testthat/_snaps/vars-pull.md @@ -29,14 +29,14 @@ Code vars_pull(letters, 100) Condition - Error in `vec_as_location2_result()`: + Error: ! Can't extract columns past the end. i Location 100 doesn't exist. i There are only 26 columns. Code vars_pull(letters, -100) Condition - Error in `vec_as_location2_result()`: + Error: ! Can't extract columns past the end. i Location 100 doesn't exist. i There are only 26 columns. @@ -69,7 +69,7 @@ Code vars_pull(letters, "foo") Condition - Error in `vec_as_location2_result()`: + Error: ! Can't extract columns that don't exist. x Column `foo` doesn't exist. From 463157e0ec0fe01f536e09886e54de72222a4c86 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 17 Aug 2022 17:54:57 -0500 Subject: [PATCH 4/5] Use dev vctrs For latest error snapshots --- DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c754329d..95f4c1b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Imports: glue (>= 1.3.0), lifecycle (>= 1.0.1.9000), rlang (>= 1.0.4), - vctrs (>= 0.4.1), + vctrs (>= 0.4.1.9000), withr Suggests: covr, @@ -41,4 +41,5 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 Remotes: - r-lib/lifecycle + r-lib/lifecycle, + r-lib/vctrs From 70585934cd3c3e4f99041890d2cd7198d4a5d76a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 18 Aug 2022 09:37:42 -0500 Subject: [PATCH 5/5] Revert to CRAN vctrs --- DESCRIPTION | 5 ++--- tests/testthat/_snaps/vars-pull.md | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95f4c1b1..c754329d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Imports: glue (>= 1.3.0), lifecycle (>= 1.0.1.9000), rlang (>= 1.0.4), - vctrs (>= 0.4.1.9000), + vctrs (>= 0.4.1), withr Suggests: covr, @@ -41,5 +41,4 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 Remotes: - r-lib/lifecycle, - r-lib/vctrs + r-lib/lifecycle diff --git a/tests/testthat/_snaps/vars-pull.md b/tests/testthat/_snaps/vars-pull.md index ed37f19a..bcf459ad 100644 --- a/tests/testthat/_snaps/vars-pull.md +++ b/tests/testthat/_snaps/vars-pull.md @@ -29,14 +29,14 @@ Code vars_pull(letters, 100) Condition - Error: + Error in `vec_as_location2_result()`: ! Can't extract columns past the end. i Location 100 doesn't exist. i There are only 26 columns. Code vars_pull(letters, -100) Condition - Error: + Error in `vec_as_location2_result()`: ! Can't extract columns past the end. i Location 100 doesn't exist. i There are only 26 columns. @@ -69,7 +69,7 @@ Code vars_pull(letters, "foo") Condition - Error: + Error in `vec_as_location2_result()`: ! Can't extract columns that don't exist. x Column `foo` doesn't exist.