1test_that("zap_label strips label but doesn't change other attributes", {
2  var <- labelled(c(1L, 98L, 99L), c(not_answered = 98L, not_applicable = 99L), label = "foo")
3  var_nolabel <- labelled(c(1L, 98L, 99L), c(not_answered = 98L, not_applicable = 99L))
4  expect_identical(zap_label(var), var_nolabel)
5})
6
7test_that("zap_label returns variables not of class('labelled') unmodified", {
8  var <- c(1L, 98L, 99L)
9  expect_equal(zap_labels(var), var)
10})
11
12test_that("zap_label is correctly applied to every column in data frame", {
13  y1_label <- labelled(10:1, c("good" = 1), label="foo")
14  y1_nolabel <- labelled(10:1, c("good" = 1))
15  y2_label <- labelled(1:10, c("bad" = 2), label="bar")
16  y2_nolabel <- labelled(1:10, c("bad" = 2))
17
18  df <- tibble::tibble(x = 1:10, y1=y1_label, y2=y2_label)
19  df_zapped <- zap_label(df)
20
21  expect_equal(ncol(df_zapped), ncol(df))
22  expect_identical(df_zapped$y1, y1_nolabel)
23  expect_identical(df_zapped$y2, y2_nolabel)
24})
25
26test_that("zap_label strips attribute from any vector", {
27  x <- structure(1:5, label = "a")
28  expect_equal(attr(zap_label(x), "label"), NULL)
29})
30