tests/testthat/test-case_match.R

test_that("works with character", {
  vec <- c("a", "b", "c", "d")

  res <- case_match(vec,
                    c("a", "b") ~ "A",
                    "c" ~ "B")

  expect_equal(res, c("A", "A", "B", NA))
})

test_that("works with numeric & .default", {
  vec <- 1:4

  res <- case_match(vec,
                    c(1, 2) ~ 1,
                    3 ~ 2,
                    .default = 3)

  expect_equal(res, c(1, 1, 2, 3))
})

Try the tidytable package in your browser

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

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.