Skip to content

Commit

Permalink
fix: flextable works with R < 4.1.0
Browse files Browse the repository at this point in the history
- drop usage of simplify with apply

fix #655
  • Loading branch information
davidgohel committed Sep 2, 2024
1 parent b59ac8a commit c7ceb26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions R/compose.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-cell_content.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit c7ceb26

Please sign in to comment.