markfairbanks / tidytable

Tidy interface to 'data.table'
https://markfairbanks.github.io/tidytable/
Other
450 stars 32 forks source link

weird error using testthat #796

Closed bnicenboim closed 9 months ago

bnicenboim commented 9 months ago

Hi, my package was failing miserably all the tests, and I discovered the culprit. The following only gives warnings if I use testthat (e.g., devtools::test_active_file() , but not interactively)

df <- data.frame(.id = 1:10, x = 1:10)
by = "x"
dots <- rlang::quos(.id == 1)
test_that("test", {
  tidytable::filter(df, !!!dots, .by = by)
})

And the by is critical for the warning, if you remove, it all works. This is what I get:

── Warning (test_temp.R:6:3): test ─────────────────────────────────────────────
Using an external vector in selections was deprecated in tidyselect 1.1.0.
i Please use `all_of()` or `any_of()` instead.
  # Was:
  data %>% select(by)

  # Now:
  data %>% select(all_of(by))

See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
Backtrace:
     ▆
  1. └─tidytable::filter(df, !!!dots, .by = by) at test_temp.R:6:3
  2.   └─tidytable:::tt_filter(...)
  3.     └─tidytable:::tidyselect_names(.df, !!.by)
  4.       └─tidytable:::tidyselect_locs(.df, ...)
  5.         └─tidyselect::eval_select(expr(c(...)), .df)
  6.           └─tidyselect:::eval_select_impl(...)
  7.             ├─tidyselect:::with_subscript_errors(...)
  8.             │ └─rlang::try_fetch(...)
  9.             │   └─base::withCallingHandlers(...)
 10.             └─tidyselect:::vars_select_eval(...)
 11.               └─tidyselect:::walk_data_tree(expr, data_mask, context_mask)
 12.                 └─tidyselect:::eval_c(expr, data_mask, context_mask)
 13.                   └─tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
 14.                     └─tidyselect:::walk_data_tree(new, data_mask, context_mask)
 15.                       └─tidyselect:::eval_sym(expr, data_mask, context_mask)
bnicenboim commented 9 months ago

Oh, I was trying the any_of in the wrong places, I see that a workaround is any_of(by). But I find it strange that the error only occurs while testing

markfairbanks commented 9 months ago

Not sure why that is only occurring when testing, but tidyselect now wants you to use any_of(by) when selecting with vectors