Preserve big.mark = " " when updating modify_header() of gt_summary object

29 Views Asked by At

Setting big.mark with

theme_gtsummary_language("en", big.mark = " ")

is handy and works. See gtsummary R package: how to remove commas when printing large numbers?

However, I struggle to find a way to preserve this formatting in the header when using modify_header()

theme_gtsummary_language("en", big.mark = " ")

ggplot2::diamonds %>%
  select(cut) %>%
  tbl_summary()%>%
  modify_header(all_stat_cols() ~ "**{level}**, \n N = {n}")

enter image description here

See the header does not have the big.mark = " " formatting.

Any hacks, workarounds or "official" code is appreciated.

  • In my own work i usually print these as a flextable so if there are any updates I can do there that can also work.
1

There are 1 best solutions below

0
Carl On

Possible workaround with scales::number():

library(gtsummary)

theme_gtsummary_language("en", big.mark = " ")

ggplot2::diamonds %>%
  select(cut) %>%
  tbl_summary() %>%
  modify_header(all_stat_cols() ~ "**{level}**, N = {scales::number(n)}")

enter image description here

Created on 2024-03-19 with reprex v2.1.0