knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(BiosCoreHub)
Latest versions of RStudio have many features that can help you writing your reports

Complicated analysis with multiple scripts are saved in the R directory and sourced when writing the RMarkdown script
Example:
knitr::opts_chunk$set(echo = FALSE, fig.align = "center") # Load the packages you need library(tidyverse) library(flextable) source('./R/analysis.R')
{width="800"}
Use tbl_summary() to summarize a data frame.
library(gtsummary) # make dataset with a few variables to summarize trial2 <- trial %>% select(age, grade, response, trt) # summarize the data with our package table1 <- tbl_summary(trial2) table1
There are many customization options to add information (like comparing groups) and format results (like bold labels) in your table. See the tbl_summary() tutorial for many more options, or below for one example.
table2 <- tbl_summary( trial2, by = trt, # split table by group missing = "no" # don't list missing data separately ) %>% add_n() %>% # add column with total number of non-missing observations add_p() %>% # test for a difference between groups modify_header(label = "**Variable**") %>% # update the column header bold_labels() table2
Use tbl_regression() to easily and beautifully display regression model results in a table. See the tutorial for customization options.
mod1 <- glm(response ~ trt + age + grade, trial, family = binomial) t1 <- tbl_regression(mod1, exponentiate = TRUE) t1
You can also present side-by-side regression model results using tbl_merge()
library(survival) # build survival model table t2 <- coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>% tbl_regression(exponentiate = TRUE) # merge tables tbl_merge_ex1 <- tbl_merge( tbls = list(t1, t2), tab_spanner = c("**Tumor Response**", "**Time to Death**") ) tbl_merge_ex1
gtsummary tables can also be saved directly to file as an image, RTF, LaTeX, and Word file.
tbl %>% as_flex_table() %>% flextable::save_as_docx()
# If you want small fonts table1 %>% as_gt() %>% gt::tab_options(table.font.size = "small")
# JAMA theme theme_gtsummary_journal(journal = "jama")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.