Skip to contents

The function ae_table_soc() creates a summary table of maximum AE grades for each patient according to term and SOC CTCAE. The resulting dataframe can be piped to as_flextable() to get a nicely formatted flextable.

Usage

ae_table_soc(
  df_ae,
  ...,
  df_enrol,
  arm = "ARM",
  term = "AETERM",
  soc = "AESOC",
  grade = "AEGR",
  subjid = "SUBJID",
  sort_by_ae = TRUE,
  total = TRUE,
  digits = 0,
  warn_miss = FALSE
)

# S3 method for class 'ae_table_soc'
as_flextable(x, arm_colors = c("#f2dcdb", "#dbe5f1", "#ebf1dd", "#e5e0ec"))

Arguments

df_ae

adverse event dataset, one row per AE, containing subjid, soc, and grade

...

unused

df_enrol

enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.

arm

name of the treatment column in df_enrol. Case-insensitive. Can be set to NULL to not group.

term

name of the the CTCAE term column in df_ae. Case-insensitive. Can be set to NULL.

soc

name of the SOC column in df_ae. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from df_ae).

grade

name of the AE grade column in df_ae. Case-insensitive.

subjid

name of the patient ID in both df_ae and df_enrol. Case-insensitive.

sort_by_ae

should the table be sorted by number or alphabetically

total

whether to add a total column for each arm

digits

significant digits for percentages

warn_miss

whether to warn for missing values

x

a dataframe, resulting of ae_table_soc()

arm_colors

colors for the arm groups

Value

a dataframe (ae_table_soc()) or a flextable (as_flextable()).

a formatted flextable

Examples


tm = edc_example_ae()
#> Warning: Option "edc_lookup" has been overwritten.
ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL)
#> # A tibble: 23 × 13
#>    soc    ctl_G1 ctl_G2 ctl_G3 ctl_G4 ctl_G5 ctl_Tot trt_G1 trt_G2 trt_G3 trt_G4
#>    <chr>  <glue> <glue> <glue> <glue> <glue> <glue>  <glue> <glue> <glue> <glue>
#>  1 Injur… 1 (4%) NA     1 (4%) 1 (4%) NA     3 (11%) 3 (13… 1 (4%) 1 (4%) NA    
#>  2 Neopl… 2 (7%) 1 (4%) NA     NA     NA     3 (11%) 2 (9%) NA     2 (9%) NA    
#>  3 Nervo… 1 (4%) 1 (4%) 3 (11… NA     NA     5 (19%) NA     NA     3 (13… NA    
#>  4 Eye d… 2 (7%) NA     2 (7%) 1 (4%) NA     5 (19%) 1 (4%) 1 (4%) NA     NA    
#>  5 Hepat… NA     2 (7%) NA     1 (4%) NA     3 (11%) 2 (9%) 1 (4%) 1 (4%) NA    
#>  6 Infec… 2 (7%) 2 (7%) 1 (4%) NA     NA     5 (19%) NA     NA     1 (4%) NA    
#>  7 Skin … NA     NA     1 (4%) 1 (4%) NA     2 (7%)  NA     2 (9%) 2 (9%) 1 (4%)
#>  8 Ear a… 1 (4%) NA     NA     NA     NA     1 (4%)  1 (4%) 1 (4%) 1 (4%) 2 (9%)
#>  9 Repro… 2 (7%) 4 (15… NA     NA     NA     6 (22%) NA     NA     NA     NA    
#> 10 Respi… 2 (7%) NA     1 (4%) 1 (4%) NA     4 (15%) NA     NA     2 (9%) NA    
#> # ℹ 13 more rows
#> # ℹ 2 more variables: trt_G5 <glue>, trt_Tot <glue>
ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL, arm=NULL)
#> # A tibble: 23 × 7
#>    soc                                all_G1 all_G2 all_G3 all_G4 all_G5 all_Tot
#>    <chr>                              <glue> <glue> <glue> <glue> <glue> <glue> 
#>  1 Injury, poisoning and procedural … 4 (8%) 1 (2%) 2 (4%) 1 (2%) 1 (2%) 9 (18%)
#>  2 Neoplasms benign, malignant and u… 4 (8%) 1 (2%) 2 (4%) NA     1 (2%) 8 (16%)
#>  3 Nervous system disorders           1 (2%) 1 (2%) 6 (12… NA     NA     8 (16%)
#>  4 Eye disorders                      3 (6%) 1 (2%) 2 (4%) 1 (2%) NA     7 (14%)
#>  5 Hepatobiliary disorders            2 (4%) 3 (6%) 1 (2%) 1 (2%) NA     7 (14%)
#>  6 Infections and infestations        2 (4%) 2 (4%) 2 (4%) NA     1 (2%) 7 (14%)
#>  7 Skin and subcutaneous tissue diso… NA     2 (4%) 3 (6%) 2 (4%) NA     7 (14%)
#>  8 Ear and labyrinth disorders        2 (4%) 1 (2%) 1 (2%) 2 (4%) NA     6 (12%)
#>  9 Reproductive system and breast di… 2 (4%) 4 (8%) NA     NA     NA     6 (12%)
#> 10 Respiratory, thoracic and mediast… 2 (4%) NA     3 (6%) 1 (2%) NA     6 (12%)
#> # ℹ 13 more rows

if (FALSE) { # \dontrun{
#the resulting flextable can be customized using the flextable package
library(flextable)
ae_table_soc(tm$ae, df_enrol=tm$enrolres, total=FALSE) %>% 
  as_flextable() %>% 
  hline(i=~soc=="" & soc!=dplyr::lead(soc))
ae_table_soc(tm$ae, df_enrol=tm$enrolres, term=NULL, sort_by_ae=FALSE) %>% 
  as_flextable() %>% 
  hline()
ae_table_soc(tm$ae, df_enrol=tm$enrolres, term=NULL, arm=NULL) %>% 
  as_flextable()
} # }