knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
library(gtsummary) library(tidyverse) library(survival)
Tables created with {gtsummary} can be integrated into R markdown documents. The {gtsummary} package was written to be a companion to the {gt} package from RStudio, and {gtsummary} tables are printed using {gt} when possible. Currently, {gt} supports HTML output, with LaTeX and RTF planned for the future.
patient_characteristics <- trial %>% select(trt, age, grade, response) %>% tbl_summary(by = trt) patient_characteristics
With HTML output, you can include complex tables with footnotes, indentation, and spanning table headers.
# Side-by-side Regression Models # logistic regression model t1 <- glm(response ~ trt + grade + age, trial, family = binomial) %>% tbl_regression(exponentiate = TRUE) # time to death Cox model t2 <- coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>% tbl_regression(exponentiate = TRUE) # printing merged table tbl_merge( tbls = list(t1, t2), tab_spanner = c("**Tumor Response**", "**Time to Death**") )
Any number/statistic from a {gtsummary} table can be reported inline in a R markdown document using the inline_text()
function. See example below:
Among patients who received Drug A,
r inline_text(patient_characteristics, variable = grade, level = "III", column = "Drug A")
had grade III tumors.
For detailed examples using functions from {gtsummary}, visit the {gtsummary} website.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.