test_that("age_in_years works as expected", {
a1 <- c(70, 7, 53, 11, 24)
u1 <- c("Year", "Week", "Year", "Month", NA_character_)
target1 <- c(70.000, 0.134, 53.000, 0.917, 24.000)
x1 <- age_in_years(a1, u1)
expect_is(x1, "numeric")
expect_length(x1, length(a1))
expect_true(all(abs(x1 - target1) < 0.001))
# test with units as plurals
a2 <- a1
u2 <- u1
u2[!is.na(u1)] <- paste0(u1[!is.na(u1)], "s")
x2 <- age_in_years(a2, u2)
expect_equal(x2, x1)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.