gtsummary
gtsummary copied to clipboard
Can I replace all `"<br>"` calls with `" \n"`?
Apart from having to type fewer, is there any advantage of the substitution to make it worth the effort? With Quarto around the corner, HTML publishing should be a bit more popular going forward, in my opinion. I suspect <br/>
should therefore do better than \n
.
The "\n" is supported by most of the output formats as a line breaker
Ok then.
Just in case it's been missed, this does not yet work in the tab_spanner
argument of tbl_merge
:
library(survival)
library(tidyverse)
library(gtsummary)
t1 <-
glm(response ~ trt + grade + age, trial, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
t2 <-
coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
tbl_regression(exponentiate = TRUE) %>%
modify_header(estimate ~ "**Coefficient\n(SE)**")
tbl_merge(
tbls = list(t1, t2),
tab_spanner = c("**Tumor\nResponse**", "**Time<br>to Death**")
)
Created on 2022-10-11 with reprex v2.0.2
For some reason, you need two spaces in front of the \n for gt tables. Idk if it'll work everywhere though. I need to do some testing when I have the time
How do you want the test done so that I can help?
Best.
How do you want the test done so that I can help?
Thanks for the offer! I am not sure what exactly needs to be done. Mostly just need to understand when " \n"
works as a line breaker and when it does not, and for what output types, and for which output engines.
Is it possible to use \n to insert a space when printing output statistics? E.g., within tbl_summary:
statistic = all_continuous() ~ "{mean} ± {sd} \n{median} ({p25}, {p75})"
If I'd like to see mean/SD on one line, followed by median/IQR on the second line?
@sss203 see example below. Please post any questions you have in the future to stackoverflow.com. When you use the gtsummary tag, I"ll be notified of the post.
trial %>%
select(age) |>
tbl_summary(
statistic =
all_continuous() ~ "{mean} ± {sd} \n{median} ({p25}, {p75})"
) |>
as_gt() |>
gt::fmt_markdown(columns = everything())
Hmm this seems to lead to some odd formatting of the rest of the table:

Will do, thanks!
Update column call to columns = all_stat_cols()