context("test-clean_hiv_status")
# Load test data
data <- system.file("testdata", "testdata-time_cohort_outcomes.rds", package = "hisreportr") %>%
readRDS()
# Call function
out <- clean_hiv_status(x = data,
.drop = TRUE)
test_that("works correctly", {
expect_equal(dim(data), dim(out))
expect_equal(class(out$hiv_status), "factor")
expect_false("hiv_tx_status" %in% names(out))
expect_true(all(is.na(out$hiv_status[is.na(data$hiv_tx_status)])))
expect_true(all(is.na(out$hiv_status[data$hiv_tx_status == "Not defined"])))
expect_true(all(
out$hiv_status[data$hiv_tx_status %in% c("HIV 1st line",
"HIV 2nd line",
"HIV 3rd line")] == "On treatment"
))
})
# Call function
out_drop_false <- clean_hiv_status(x = data,
.drop = FALSE)
test_that("drop false works", {
expect_true(ncol(out_drop_false) - ncol(data) == 1)
expect_true("hiv_tx_status" %in% names(out_drop_false))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.