context("switch_labels()")
df_test_ok <- data.frame(
a = 1,
b = 2
)
attr(df_test_ok$a, "label") <- "a label"
df_test_replicate_label <- data.frame(
a = 1,
b = 2
)
attr(df_test_replicate_label$a, "label") <- "a label"
attr(df_test_replicate_label$b, "label") <- "a label"
test_that("switch_labels works on proper data.frame:", {
str_names <- names(switch_labels(df_test_ok))
expect(
all(str_names == c("a label", "b")),
"labels not properly switched"
)
})
test_that("switch_labels throws proper warning and ignores replicate labels:", {
expect_warning(
str_names <- names(switch_labels(df_test_replicate_label))
)
expect(
all(str_names == c("a label", "b")),
"labels not properly switched"
)
})
test_that("switch_labels correctly handles remove_prefix:", {
expect_warning(
str_names <- names(switch_labels(df_test_replicate_label, remove_prefix = 2))
)
expect(
all(str_names == c("label", "b")),
"labels not properly switched"
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.