knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# install.packages("gtreg") library(gtreg) library(gtsummary)
As {gtreg} is built upon {gtsummary}, you can use the same methods you
would use for {gtsummary} to output tables to various formats.
A {gtreg} table can be exported with {gt}, {flextable}, {huxtable}, {kableExtra}, knitr::kable()
, and as a tibble.
See the print engines available in {gtsummary} for details.
Here, we share approaches to common requests and recommendations for each output type.
table1 <- df_adverse_events %>% tbl_ae( id = patient_id, id_df = df_patient_characteristics, ae = adverse_event, soc = system_organ_class, by = grade ) %>% modify_header( all_ae_cols() ~ "**Grade {by}**" ) %>% bold_labels()
The default output type is HTML.
table1
Leverage the {flextable} package for word output.
table1 %>% as_flex_table() %>% flextable::save_as_docx(path = "misc/ae_table.docx")
Leverage the {huxtable} package for excel output.
table1 %>% as_hux_xlsx( file = "misc/ae_table.xlsx" )
Leverage the {kableExtra} package for styled PDF output.
To export to PDF, create a new .Rmd
or .qmd
document with a PDF output type.
The YAML shown here is for .Rmd
.
You can then use as_kable_extra()
to convert the table to the LaTeX required for pdf rendering, and kable_styling()
for extra styling of the table.
For more pdf styling options, see the blog post Report Ready PDF tables with rmarkdown, knitr, kableExtra, and LaTeX.
--- output: pdf_document --- <stuff> ```r table1 %>% as_kable_extra( booktabs = TRUE ) %>% kableExtra::kable_styling( latex_options = "striped", stripe_color = "gray!15" ) ```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.