test_that("age_from_dob works as expected", {
x1 <- c("2001-04-05", "1976-10-24", "1990-03-15", "1943-12-08", NA_character_)
a1 <- age_from_dob(x1, until = as.Date("2020-01-01"))
expect_is(a1, "integer")
expect_equal(a1, c(18L, 43L, 29L, 76L, NA_integer_))
# ensure same result when dob already of class date
a2 <- age_from_dob(as.Date(x1), until = as.Date("2020-01-01"))
expect_true(all(a2 == a1 | is.na(a2) & is.na(a1)))
# test as_int argument: numeric values > floored integer values
a3 <- age_from_dob(x1, until = as.Date("2020-01-01"), as_int = FALSE)
expect_is(a3, "numeric")
expect_true(all(a3 >= a2 | is.na(a3) & is.na(a2)))
# test until argument: ages to current date > ages to 2020-01-01
a4 <- age_from_dob(x1, as_int = FALSE)
expect_true(all(a4 > a3 | is.na(a4) & is.na(a3)))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.