tests/testthat/test-helpers-where.R

test_that("where() selects with a predicate", {
  expect_identical(select_loc(iris, where(is.factor)), c(Species = 5L))
  expect_identical(select_loc(iris, where(~ is.factor(.x))), c(Species = 5L))
})

test_that("where() checks return values", {
  expect_snapshot(error = TRUE, {
    where(NA)
  })

  expect_snapshot(error = TRUE, {
    select_loc(iris, where(~NA))
    select_loc(iris, where(~1))
    select_loc(iris, where(mean))
  })
})

Try the tidyselect package in your browser

Any scripts or data that you put into this service are public.

tidyselect documentation built on May 29, 2024, 6:07 a.m.