tests/testthat/test_switch_labels.R

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"
  )

})
kkmann/CENTERTBI documentation built on May 23, 2019, 8:51 a.m.