diff --git a/DESCRIPTION b/DESCRIPTION index 0b8dff25..57d0b88c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: flextable Title: Functions for Tabular Reporting -Version: 0.9.7.010 +Version: 0.9.7.011 Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), person("ArData", role = "cph"), diff --git a/R/compose.R b/R/compose.R index 710fe090..ab2bfa32 100644 --- a/R/compose.R +++ b/R/compose.R @@ -199,14 +199,14 @@ labelizor <- function(x, j = NULL, labels, part = "all") { x$txt[x$txt %in% levs] <- labs[match(x$txt, levs, nomatch = 0)] x }) - }, simplify = FALSE) + }) } else { newcontent <- apply(curr_content_columns, 2, function(x) { lapply(x, function(x) { x$txt <- labels(x$txt) x }) - }, simplify = FALSE) + }) } newcontent <- as_chunkset_struct( l_paragraph = do.call(c, newcontent), diff --git a/tests/testthat/test-cell_content.R b/tests/testthat/test-cell_content.R index 4c9ef185..cb10f048 100644 --- a/tests/testthat/test-cell_content.R +++ b/tests/testthat/test-cell_content.R @@ -149,3 +149,20 @@ test_that("delete rows and columns", { ) }) + +test_that("labelizor", { + zzz <- CO2[,-c(1, 4)] + zzz[1,1] <- NA + zzz[47,1] <- NA + + z <- summarizor(x = zzz, by = "Treatment", overall_label = "Overall") + ftab <- as_flextable(z, separate_with = "variable") + ftab <- labelizor( + x = ftab, j = c("stat", "nonchilled@blah"), + labels = c(Missing = "Kouign amann", "20 (47.6%)" = "plop") + ) + chunk_txt <- information_data_chunk(ftab)$txt + expect_equal(chunk_txt[32], expected = "Kouign amann") + expect_equal(chunk_txt[18], expected = "plop") + expect_equal(chunk_txt[26], expected = "plop") +})