Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate .data #295

Merged
merged 8 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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.9000),
withr
Expand All @@ -41,3 +42,5 @@ Config/Needs/website: tidyverse/tidytemplate
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
Remotes:
r-lib/lifecycle
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

* `eval_select()` out-of-bounds errors now use the verb "select" rather than
"subset" in the error message for consistency with `dplyr::select()` (#271).

Expand Down
5 changes: 5 additions & 0 deletions R/eval-walk.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,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")
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/eval-walk.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@
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.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

# eval_walk() has informative messages

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-eval-walk.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should force verbosity so the test is reproducible within sessions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lifecycle always warns in tests.

expect_snapshot(x <- select_loc(x, .data$a))
})

test_that(".data in env-expression has the lexical definition", {
quo <- local({
.data <- mtcars
Expand Down Expand Up @@ -335,6 +342,7 @@ test_that("eval_sym() still supports predicate functions starting with `is`", {
})

test_that("eval_walk() has informative messages", {
withr::local_options(lifecycle_verbosity = "quiet")
reset_warning_verbosity("tidyselect::predicate_warn_is_integer")
reset_warning_verbosity("tidyselect::predicate_warn_is.numeric")
reset_warning_verbosity("tidyselect::predicate_warn_isTRUE")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-lifecycle-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,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"))
})

Expand Down