Skip to content

Commit 793b95e

Browse files
committed
add test
1 parent ffa162f commit 793b95e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/testthat/test-data_codebook.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,35 @@ test_that("data_codebook, tagged NA", {
549549
"--------------------------------------------------------------------"
550550
)
551551
)
552+
553+
x <- labelled(
554+
x = c(
555+
1:3, tagged_na("a", "c"),
556+
4:1, tagged_na("a", "a", "c"),
557+
1:3, tagged_na("c", "c"),
558+
1:4, tagged_na("a", "c")
559+
),
560+
labels = c(
561+
"Agreement" = 1, "Disagreement" = 4,
562+
"First" = tagged_na("c"), "Refused" = tagged_na("a"),
563+
"Not home" = tagged_na("z")
564+
)
565+
)
566+
out <- capture.output(data_codebook(data.frame(x)))
567+
expect_equal(
568+
out,
569+
c(
570+
"data.frame(x) (23 rows and 1 variables, 1 shown)",
571+
"",
572+
"ID | Name | Type | Missings | Values | Value Labels | N",
573+
"---+------+---------+-----------+--------+--------------+----------",
574+
"1 | x | numeric | 9 (39.1%) | 1 | Agreement | 4 (17.4%)",
575+
" | | | | 2 | 2 | 4 (17.4%)",
576+
" | | | | 3 | 3 | 4 (17.4%)",
577+
" | | | | 4 | Disagreement | 2 ( 8.7%)",
578+
" | | | | NA(a) | Refused | 4 (17.4%)",
579+
" | | | | NA(c) | First | 5 (21.7%)",
580+
"-------------------------------------------------------------------"
581+
)
582+
)
552583
})

0 commit comments

Comments
 (0)