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")) })