knitr::opts_chunk$set(echo = TRUE)
library(r2rtf) library(dplyr) library(tidyr)
This example shows how to create a simplified adverse events summary table as below.
knitr::include_graphics("pdf/ae_example.pdf")
data(r2rtf_adae) ae_t1 <- r2rtf_adae %>% group_by(TRTA) %>% mutate(n_subj = n_distinct(USUBJID)) %>% group_by(TRTA, AEDECOD) %>% summarise( n_ae = n_distinct(USUBJID), pct = round(n_ae / unique(n_subj) * 100, 2) ) %>% dplyr::filter(n_ae > 5) %>% # only show AE terms with at least 5 subjects in one treatment group. pivot_longer(cols = c(n_ae, pct), names_to = "var", values_to = "value") %>% unite(temp, TRTA, var) %>% pivot_wider(names_from = temp, values_from = value, values_fill = 0)
knitr::kable(ae_t1)
ae_tbl <- ae_t1 %>% rtf_title( "Analysis of Subjects With Specific Adverse Events", c( "(Incidence > 5 Subjects in One or More Treatment Groups)", "ASaT" ) ) %>% rtf_colheader(" | Placebo | Drug High Dose | Drug Low Dose", col_rel_width = c(4, rep(2, 3)) ) %>% rtf_colheader(" | n | (%) | n | (%) | n | (%)", col_rel_width = c(4, rep(1, 6)), border_top = c("", rep("single", 6)), border_left = c("single", rep(c("single", ""), 3)) ) %>% rtf_body( col_rel_width = c(4, rep(1, 6)), text_justification = c("l", rep("c", 6)), border_left = c("single", rep(c("single", ""), 3)) ) %>% rtf_footnote(c("{^\\dagger}This is footnote 1", "This is footnote 2"), ) %>% rtf_source("Source: xxx")
# Output .rtf file ae_tbl %>% rtf_encode() %>% write_rtf("rtf/ae_example.rtf")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.