tests/testthat/test-coalesce.R

context("coalesce")

test_that("non-missing scalar replaces all missing values", {
  x <- c(NA, 1)
  expect_equal(coalesce(x, 1), c(1, 1))
})

test_that("finds non-missing values in multiple positions", {
  x1 <- c(1L, NA, NA)
  x2 <- c(NA, 2L, NA)
  x3 <- c(NA, NA, 3L)

  expect_equal(coalesce(x1, x2, x3), 1:3)
})

test_that("error if invalid length", {
  expect_error(coalesce(1:2, 1:3), "Vector 1 is length 3 not 1 or 2")
})
sctyner/dplyr050 documentation built on May 17, 2019, 2:22 p.m.