ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.04k stars 114 forks source link

Can I replace all `"<br>"` calls with `" \n"`? #1311

Closed ddsjoberg closed 1 year ago

kwakuduahc1 commented 2 years ago

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.

ddsjoberg commented 2 years ago

The "\n" is supported by most of the output formats as a line breaker

kwakuduahc1 commented 2 years ago

Ok then.

kendonB commented 1 year ago

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**")
)

image

Created on 2022-10-11 with reprex v2.0.2

ddsjoberg commented 1 year ago

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

kwakuduahc1 commented 1 year ago

How do you want the test done so that I can help?

Best.

ddsjoberg commented 1 year ago

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.

swarupswaminathan commented 1 year ago

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?

ddsjoberg commented 1 year ago

@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())
swarupswaminathan commented 1 year ago

Hmm this seems to lead to some odd formatting of the rest of the table:

Screenshot 2023-03-01 at 10 27 28 AM

Will do, thanks!

ddsjoberg commented 1 year ago

Update column call to columns = all_stat_cols()