library(onezero)
oz <- c(0, 1, NA)
oz.log <- c(TRUE, NA)
not.oz <- c(2, 1, NA)
not.oz.chr <- c("foo")
test_that("is_onezero is correctly identifying vectors", {
expect_true(is_onezero(oz))
expect_false(is_onezero(not.oz))
expect_true(is_onezero(oz.log))
expect_false(is_onezero(not.oz.chr))
})
test_that("onezero is properly converting vectors", {
expect_true(is_onezero(onezero(not.oz, one_values = 1, zero_values = 2)))
expect_true(is_onezero(onezero(not.oz, one_values = 1)))
expect_true(is_onezero(onezero(not.oz, one_values = 1, keep.na = FALSE)))
expect_true(is_onezero(onezero(not.oz.chr, one_values = "foo")))
})
test_that("onezero stops and warns correctly", {
expect_error(onezero(x = not.oz, zero_values = 2))
expect_warning(onezero(not.oz, one_values = c(2, 1), zero_values = 1))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.