Debian Codegraph @

inst/tests/test-missing.R

raw
1 library(testthat)
2 library(pander)
3
4 context('replacing missing values')
5
6 pom <- panderOptions('missing')
7
8 panderOptions('missing', '<missing>')
9 test_that('replacing missing values works with string', {
10 expect_equal(pander_return(c(1, NA)), '_1_ and _<missing>_')
11 expect_equal(paste(pander_return(list(1, NA)), collapse = '\n'),
12 '\n\n * _1_\n * <missing>\n\n<!-- end of list -->\n\n')
13 expect_equal(paste(pander_return(
14 data.frame(a = 1:2, b = c(1, NA), c = c(NA, 'z'))),
15 collapse = '\n'),
16 '\n---------------------------\n a b c \n--- ----------- -----------\n 1 1 <missing> \n\n 2 <missing> z \n---------------------------\n') #nolint
17 })
18
19 panderOptions('missing', '')
20 test_that('suppressing missing values works', {
21 expect_equal(pander_return(c(1, NA)), '_1_ and __')
22 expect_equal(paste(pander_return(list(1, NA)), collapse = '\n'),
23 '\n\n * _1_\n *\n\n<!-- end of list -->\n\n')
24 expect_equal(paste(pander_return(data.frame(a = 1:2, b = c(1, NA), c = c(NA, 'z'))), collapse = '\n'),
25 '\n-----------\n a b c \n--- --- ---\n 1 1 \n\n 2 z \n-----------\n')
26 })
27
28 panderOptions('missing', pom)