context("which_pattern")
test_that("which_pattern works correctly", {
expect_equal(
which_pattern(month.name, c("^J", "[A,a]", "[O,o]")),
c(1, 2, 2, 2, 2, 1, 1, 2, NA, 3, 3, NA)
)
expect_equal(
which_pattern(month.name, c("[A,a]", "^J", "[O,o]")),
c(1, 1, 1, 1, 1, 2, 2, 1, NA, 3, 3, NA)
)
expect_equal(which_pattern("c", c("a", "b", "c")), 3)
expect_equal(which_pattern(c("a", "b", "c"), "c"), c(NA, NA, 1))
})
test_that("patband works correctly", {
seasons <- list(
Wi = c("De", "Ja", "Fe"),
Sp = c("Ma", "Ap"),
Su = c("Ju", "Au"),
Au = c("Se", "Oc", "No")
)
expect_equal(
patband(month.name, seasons, as.factor = TRUE),
factor(c(tail(rep(names(seasons), each = 3), -1), "Wi"), levels = names(seasons))
)
expect_equal(patband("January", seasons), patband("December", seasons))
quarters <- list(
c("Ja", "Fe", "Mar"),
c("Ap", "May", "Jun"),
c("Jul", "Au", "Se"),
c("Oc", "No", "De")
)
expect_equal(
patband(month.name, quarters),
rep(1:4, each = 3)
)
expect_equal(patband("January", quarters), 1)
expect_equal(patband("December", quarters), 4)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.