Skip to content

Commit

Permalink
Properly escape < and > if they appear in the column headings in LaTe…
Browse files Browse the repository at this point in the history
…X tables.
  • Loading branch information
jan-imbi committed Jan 30, 2024
1 parent 6b7e5a5 commit f157380
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: DescrTab2
Type: Package
Title: Publication Quality Descriptive Statistics Tables
Version: 2.1.25
Date: 2023-12-15
Version: 2.1.26
Date: 2024-01-30
Authors@R: c(person("Jan", "Meis", role = c("aut", "cre"), email="[email protected]", comment = c(ORCID = "0000-0001-5407-7220")),
person("Lukas", "Baumann", role = c("aut"), comment = c(ORCID = "0000-0001-7931-7470")),
person("Maximilian", "Pilz", role = c("aut"), comment = c(ORCID = "0000-0002-9685-1613")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 2.1.26

* Properly escape < and > if they appear in the column headings in LaTeX tables.

# Version 2.1.25

* Throw an error if a group level is called "Total", "Variable", "p", "test_name", "CI", or "CI_name".
Expand Down
8 changes: 5 additions & 3 deletions R/descr.R
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,10 @@ if ("CI_name" %in% names(tibl)) {

alig <- paste0(c("l", rep("c", ncol(tibl) - 1)), collapse = "")
alig2 <- paste0(c("l", rep("c", ncol(tibl) - 1)))
actual_colnames <- names(tibl[!indx_varnames, ])

actual_colnames <- names(tibl[!indx_varnames, ]) |>
as_tibble() |>
escape_latex_symbols(numEscapes = 2) |>
pull(value)

N_numbers <-
c("", paste0("(N=", DescrPrintObj[["group"]][["lengths"]][DescrPrintObj[["group_labels"]] %in% names(tibl)], ")"))
Expand Down Expand Up @@ -1424,7 +1426,7 @@ if ("CI_name" %in% names(tibl)) {
) %>%
column_spec(1, width = paste0(width + 1, "em")) %>%
kableExtra::pack_rows(index = lengths, latex_gap_space = "0.5cm", escape = FALSE) %>%
add_header_above(actual_colnames, line = FALSE, align = alig2) %>%
add_header_above(actual_colnames, line = FALSE, align = alig2, escape = FALSE) %>%
kable_styling(
latex_options = "repeat_header",
repeat_header_continued = FALSE
Expand Down

0 comments on commit f157380

Please sign in to comment.