tests/testthat/test-if_else.R

test_that("works with true = NA", {
  x <- 1:4

  res <- if_else(x > 2L, NA, x - 1L)

  expect_equal(res, c(0, 1, NA, NA))
})

test_that("works with false = NA", {
  x <- 1:4

  res <- if_else(x > 2L, x - 1L, NA)

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

test_that("if_else. works", {
  x <- 1:4

  res <- if_else.(x > 2L, NA, x - 1L) %>%
    suppressWarnings()

  expect_equal(res, c(0, 1, NA, NA))
})

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.