# Define tests ----
structure_tests <- quote({
expect_true(is.data.frame(out))
expect_equal(ncol(out), 2)
expect_true(any(grepl("^fu_", names(out))))
expect_equal(length(unique(data$id)), length(out$id))
expect_equal(length(unique(out$id)), length(out$id))
})
fu_6m_tests <- quote({
expect_true(out$fu_6_months[out$id == 1] == "a")
expect_true(out$fu_6_months[out$id == 2] == "c")
expect_true(is.na(out$fu_6_months[out$id == 3]))
})
fu_12m_tests <- quote({
expect_true(any(grepl("^fu_12", names(out))))
expect_true(all(is.na(out$fu_12_months)))
})
fu_12m_tests_new_reporting_date <- quote({
expect_true(out$fu_12_months[out$id == 1] == "b")
expect_true(out$fu_12_months[out$id == 2] == "c")
expect_true(out$fu_12_months[out$id == 3] == "b")
})
# Load test data ----
data <- readRDS(system.file("testdata", "testdata-outcome_by_followup_time.rds", package = "hisreportr"))
# Call with 6M follow-up ----
out <- outcome_by_followup_time(followup_month = 6,
df = data,
reporting_date = lubridate::dmy("1/7/2010"),
start_var = "starttre",
date_var = "date",
id_var = "id",
status_var = "status")
# Execute tests 6M follow-up tests ----
test_that("Structure ok", eval(structure_tests))
test_that("6M ok", eval(fu_6m_tests))
# Call with 12M follow-up ----
out <- outcome_by_followup_time(followup_month = 12,
df = data,
reporting_date = lubridate::dmy("1/7/2010"),
start_var = "starttre",
date_var = "date",
id_var = "id",
status_var = "status")
# Execute tests 12M follow-up tests ----
test_that("Structure ok", eval(structure_tests))
test_that("12M ok", eval(fu_12m_tests))
# Call with 12M follow-up and correct reporting date ----
out <- outcome_by_followup_time(followup_month = 12,
df = data,
reporting_date = lubridate::dmy("1/4/2011"),
start_var = "starttre",
date_var = "date",
id_var = "id",
status_var = "status")
# Execute tests 12M with new reporting date ----
test_that("Structure ok", eval(structure_tests))
test_that("12M new reporting date ok", eval(fu_12m_tests_new_reporting_date))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.