How can I obtain literal curly brackets in tbl_summary?
Here is what I tried:
> gtsummary::tbl_summary(mtcars,statistic = all_continuous() ~ "\\makecell{{{mean}}}")
Error in `gtsummary::tbl_summary()`:
! Problem with the `statistic` argument.
Error converting string "{{mean" to a function.
ℹ Is the name spelled correctly and available?
Run `rlang::last_trace()` to see where the error occurred.
Because of the way tbl_summary() processes the statistic argument, this does not seem directly possible at the moment.
Therefore, one option would be to post-process the output like so:
library(gtsummary)
# insert placeholders
x <- tbl_summary(
mtcars,
statistic = list(all_continuous() ~ "curly_open{mean}curly_close")
)
# remove placeholders from footnote
x$table_styling$footnote <- x$table_styling$footnote |>
mutate(
footnote = sub("curly_open", "", footnote),
footnote = sub("curly_close", "", footnote)
)
# replace placeholders in body
x$table_body <- x$table_body |>
mutate(
stat_0 = sub("curly_open", "{", stat_0),
stat_0 = sub("curly_close", "}", stat_0)
)
# print
x

Created on 2025-01-16 with reprex v2.1.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With