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.

ae_table_soc(
  df_ae,
  ...,
  df_enrol,
  variant = c("max", "sup", "eq"),
  arm = NULL,
  term = NULL,
  sort_by_count = TRUE,
  total = TRUE,
  showNA = TRUE,
  digits = 0,
  warn_miss = FALSE,
  grade = "AEGR",
  soc = "AESOC",
  subjid = "SUBJID"
)

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

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.

variant

one or several of c("max", "sup", "eq"). max computes the maximum AE grade per patient, sup computes the number of patients having experienced at least one AE of grade higher or equal to X, and eq computes the number of patients having experienced at least one AE of grade equal to X.

arm

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

term

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

sort_by_count

should the table be sorted by the number of AE or by SOC alphabetically.

total

whether to add a total column for each arm.

showNA

whether to display missing grades.

digits

significant digits for percentages.

warn_miss

whether to warn for missing values.

grade

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

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).

subjid

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

x

a dataframe, resulting of ae_table_soc()

arm_colors

colors for the arm groups

padding_v

a numeric of lenght up to 2, giving the vertical padding of body (1) and header (2)

Value

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

a formatted flextable

Examples

tm = grstat_example()
attach(tm, warn.conflicts=FALSE)

ae_table_soc(df_ae=ae, df_enrol=enrolres)
#> # A tibble: 27 × 8
#>    soc           all_patients_G1 all_patients_G2 all_patients_G3 all_patients_G4
#>    <fct>         <glue>          <glue>          <glue>          <glue>         
#>  1 Investigatio… 3 (6%)          4 (8%)          2 (4%)          2 (4%)         
#>  2 Immune syste… 3 (6%)          2 (4%)          3 (6%)          2 (4%)         
#>  3 General diso… 4 (8%)          1 (2%)          NA              2 (4%)         
#>  4 Infections a… 2 (4%)          4 (8%)          2 (4%)          NA             
#>  5 Congenital, … 3 (6%)          3 (6%)          1 (2%)          NA             
#>  6 Pregnancy, p… 3 (6%)          NA              3 (6%)          1 (2%)         
#>  7 Psychiatric … 2 (4%)          5 (10%)         NA              NA             
#>  8 Social circu… 4 (8%)          1 (2%)          2 (4%)          NA             
#>  9 Cardiac diso… 3 (6%)          2 (4%)          NA              1 (2%)         
#> 10 Endocrine di… 1 (2%)          3 (6%)          2 (4%)          NA             
#> # ℹ 17 more rows
#> # ℹ 3 more variables: all_patients_G5 <glue>, all_patients_NA <glue>,
#> #   all_patients_Tot <glue>
ae_table_soc(df_ae=ae, df_enrol=enrolres, arm="arm")
#> # A tibble: 27 × 15
#>    soc         control_G1 control_G2 control_G3 control_G4 control_G5 control_NA
#>    <fct>       <glue>     <glue>     <glue>     <glue>     <glue>     <glue>    
#>  1 Investigat… 2 (8%)     3 (12%)    1 (4%)     2 (8%)     1 (4%)     NA        
#>  2 Immune sys… 2 (8%)     NA         2 (8%)     NA         NA         NA        
#>  3 General di… 2 (8%)     NA         NA         NA         1 (4%)     NA        
#>  4 Infections… 2 (8%)     2 (8%)     2 (8%)     NA         NA         NA        
#>  5 Congenital… 2 (8%)     2 (8%)     1 (4%)     NA         NA         NA        
#>  6 Pregnancy,… 1 (4%)     NA         3 (12%)    1 (4%)     NA         NA        
#>  7 Psychiatri… 1 (4%)     2 (8%)     NA         NA         NA         NA        
#>  8 Social cir… 2 (8%)     1 (4%)     1 (4%)     NA         NA         NA        
#>  9 Cardiac di… 2 (8%)     2 (8%)     NA         1 (4%)     NA         NA        
#> 10 Endocrine … 1 (4%)     2 (8%)     NA         NA         NA         NA        
#> # ℹ 17 more rows
#> # ℹ 8 more variables: control_Tot <glue>, treatment_G1 <glue>,
#> #   treatment_G2 <glue>, treatment_G3 <glue>, treatment_G4 <glue>,
#> #   treatment_G5 <glue>, treatment_NA <glue>, treatment_Tot <glue>

#sub population
ae_table_soc(df_ae=ae, df_enrol=head(enrolres, 10), arm="arm")
#> # A tibble: 19 × 15
#>    soc         control_G1 control_G2 control_G3 control_G4 control_G5 control_NA
#>    <fct>       <glue>     <glue>     <glue>     <glue>     <glue>     <glue>    
#>  1 Immune sys… NA         NA         2 (33%)    NA         NA         NA        
#>  2 Infections… 2 (33%)    NA         NA         NA         NA         NA        
#>  3 Respirator… NA         1 (17%)    1 (17%)    NA         NA         NA        
#>  4 Blood and … NA         NA         NA         NA         NA         NA        
#>  5 Investigat… NA         1 (17%)    NA         1 (17%)    NA         NA        
#>  6 Pregnancy,… NA         NA         NA         1 (17%)    NA         NA        
#>  7 Social cir… 1 (17%)    NA         NA         NA         NA         NA        
#>  8 Cardiac di… NA         1 (17%)    NA         NA         NA         NA        
#>  9 Congenital… 1 (17%)    NA         NA         NA         NA         NA        
#> 10 Eye disord… NA         NA         NA         NA         NA         NA        
#> 11 Gastrointe… 1 (17%)    NA         NA         NA         NA         NA        
#> 12 Hepatobili… NA         1 (17%)    NA         NA         NA         NA        
#> 13 Injury, po… NA         1 (17%)    NA         NA         NA         NA        
#> 14 Metabolism… NA         NA         NA         NA         NA         NA        
#> 15 Musculoske… NA         1 (17%)    NA         NA         NA         NA        
#> 16 Psychiatri… NA         1 (17%)    NA         NA         NA         NA        
#> 17 Renal and … 1 (17%)    NA         NA         NA         NA         NA        
#> 18 Reproducti… NA         NA         1 (17%)    NA         NA         NA        
#> 19 Surgical a… NA         NA         NA         NA         NA         NA        
#> # ℹ 8 more variables: control_Tot <glue>, treatment_G1 <glue>,
#> #   treatment_G2 <glue>, treatment_G3 <glue>, treatment_G4 <glue>,
#> #   treatment_G5 <glue>, treatment_NA <glue>, treatment_Tot <glue>

#the resulting flextable can be customized using the flextable package
library(flextable)
ae_table_soc(ae, df_enrol=enrolres, total=FALSE) %>%
  as_flextable() %>%
  hline(i=~soc=="" & soc!=dplyr::lead(soc))

All patients (N=50)

CTCAE SOC

G1

G2

G3

G4

G5

NA

Investigations

3 (6%)

4 (8%)

2 (4%)

2 (4%)

1 (2%)

Immune system disorders

3 (6%)

2 (4%)

3 (6%)

2 (4%)

General disorders and administration site conditions

4 (8%)

1 (2%)

2 (4%)

1 (2%)

Infections and infestations

2 (4%)

4 (8%)

2 (4%)

Congenital, familial and genetic disorders

3 (6%)

3 (6%)

1 (2%)

Pregnancy, puerperium and perinatal conditions

3 (6%)

3 (6%)

1 (2%)

Psychiatric disorders

2 (4%)

5 (10%)

Social circumstances

4 (8%)

1 (2%)

2 (4%)

Cardiac disorders

3 (6%)

2 (4%)

1 (2%)

Endocrine disorders

1 (2%)

3 (6%)

2 (4%)

Gastrointestinal disorders

1 (2%)

1 (2%)

1 (2%)

3 (6%)

Reproductive system and breast disorders

5 (10%)

1 (2%)

Blood and lymphatic system disorders

2 (4%)

2 (4%)

1 (2%)

Metabolism and nutrition disorders

2 (4%)

1 (2%)

1 (2%)

1 (2%)

Neoplasms benign, malignant, and unspecified

3 (6%)

2 (4%)

Respiratory, thoracic and mediastinal disorders

1 (2%)

2 (4%)

1 (2%)

1 (2%)

Surgical and medical procedures

2 (4%)

3 (6%)

Musculoskeletal and connective tissue disorders

2 (4%)

2 (4%)

Eye disorders

2 (4%)

1 (2%)

Hepatobiliary disorders

2 (4%)

1 (2%)

Injury, poisoning and procedural complications

1 (2%)

2 (4%)

Nervous system disorders

1 (2%)

1 (2%)

1 (2%)

Renal and urinary disorders

2 (4%)

1 (2%)

Skin and subcutaneous tissue disorders

2 (4%)

1 (2%)

Vascular disorders

1 (2%)

1 (2%)

Ear and labyrinth disorders

1 (2%)

No Declared AE

1 (2%)

ae_table_soc(ae, df_enrol=enrolres, term=NULL, sort_by_count=FALSE) %>% as_flextable() %>% bold(i=~soc=="Eye disorders")

All patients (N=50)

CTCAE SOC

G1

G2

G3

G4

G5

NA

Tot

Blood and lymphatic system disorders

2 (4%)

2 (4%)

1 (2%)

5 (10%)

Cardiac disorders

3 (6%)

2 (4%)

1 (2%)

6 (12%)

Congenital, familial and genetic disorders

3 (6%)

3 (6%)

1 (2%)

7 (14%)

Ear and labyrinth disorders

1 (2%)

1 (2%)

Endocrine disorders

1 (2%)

3 (6%)

2 (4%)

6 (12%)

Eye disorders

2 (4%)

1 (2%)

3 (6%)

Gastrointestinal disorders

1 (2%)

1 (2%)

1 (2%)

3 (6%)

6 (12%)

General disorders and administration site conditions

4 (8%)

1 (2%)

2 (4%)

1 (2%)

8 (16%)

Hepatobiliary disorders

2 (4%)

1 (2%)

3 (6%)

Immune system disorders

3 (6%)

2 (4%)

3 (6%)

2 (4%)

10 (20%)

Infections and infestations

2 (4%)

4 (8%)

2 (4%)

8 (16%)

Injury, poisoning and procedural complications

1 (2%)

2 (4%)

3 (6%)

Investigations

3 (6%)

4 (8%)

2 (4%)

2 (4%)

1 (2%)

12 (24%)

Metabolism and nutrition disorders

2 (4%)

1 (2%)

1 (2%)

1 (2%)

5 (10%)

Musculoskeletal and connective tissue disorders

2 (4%)

2 (4%)

4 (8%)

Neoplasms benign, malignant, and unspecified

3 (6%)

2 (4%)

5 (10%)

Nervous system disorders

1 (2%)

1 (2%)

1 (2%)

3 (6%)

Pregnancy, puerperium and perinatal conditions

3 (6%)

3 (6%)

1 (2%)

7 (14%)

Psychiatric disorders

2 (4%)

5 (10%)

7 (14%)

Renal and urinary disorders

2 (4%)

1 (2%)

3 (6%)

Reproductive system and breast disorders

5 (10%)

1 (2%)

6 (12%)

Respiratory, thoracic and mediastinal disorders

1 (2%)

2 (4%)

1 (2%)

1 (2%)

5 (10%)

Skin and subcutaneous tissue disorders

2 (4%)

1 (2%)

3 (6%)

Social circumstances

4 (8%)

1 (2%)

2 (4%)

7 (14%)

Surgical and medical procedures

2 (4%)

3 (6%)

5 (10%)

Vascular disorders

1 (2%)

1 (2%)

2 (4%)

No Declared AE

1 (2%)

1 (2%)

ae_table_soc(ae, df_enrol=enrolres, term=NULL, arm=NULL) %>% as_flextable() %>% highlight(i=~soc=="Hepatobiliary disorders", j="all_patients_Tot")

All patients (N=50)

CTCAE SOC

G1

G2

G3

G4

G5

NA

Tot

Investigations

3 (6%)

4 (8%)

2 (4%)

2 (4%)

1 (2%)

12 (24%)

Immune system disorders

3 (6%)

2 (4%)

3 (6%)

2 (4%)

10 (20%)

General disorders and administration site conditions

4 (8%)

1 (2%)

2 (4%)

1 (2%)

8 (16%)

Infections and infestations

2 (4%)

4 (8%)

2 (4%)

8 (16%)

Congenital, familial and genetic disorders

3 (6%)

3 (6%)

1 (2%)

7 (14%)

Pregnancy, puerperium and perinatal conditions

3 (6%)

3 (6%)

1 (2%)

7 (14%)

Psychiatric disorders

2 (4%)

5 (10%)

7 (14%)

Social circumstances

4 (8%)

1 (2%)

2 (4%)

7 (14%)

Cardiac disorders

3 (6%)

2 (4%)

1 (2%)

6 (12%)

Endocrine disorders

1 (2%)

3 (6%)

2 (4%)

6 (12%)

Gastrointestinal disorders

1 (2%)

1 (2%)

1 (2%)

3 (6%)

6 (12%)

Reproductive system and breast disorders

5 (10%)

1 (2%)

6 (12%)

Blood and lymphatic system disorders

2 (4%)

2 (4%)

1 (2%)

5 (10%)

Metabolism and nutrition disorders

2 (4%)

1 (2%)

1 (2%)

1 (2%)

5 (10%)

Neoplasms benign, malignant, and unspecified

3 (6%)

2 (4%)

5 (10%)

Respiratory, thoracic and mediastinal disorders

1 (2%)

2 (4%)

1 (2%)

1 (2%)

5 (10%)

Surgical and medical procedures

2 (4%)

3 (6%)

5 (10%)

Musculoskeletal and connective tissue disorders

2 (4%)

2 (4%)

4 (8%)

Eye disorders

2 (4%)

1 (2%)

3 (6%)

Hepatobiliary disorders

2 (4%)

1 (2%)

3 (6%)

Injury, poisoning and procedural complications

1 (2%)

2 (4%)

3 (6%)

Nervous system disorders

1 (2%)

1 (2%)

1 (2%)

3 (6%)

Renal and urinary disorders

2 (4%)

1 (2%)

3 (6%)

Skin and subcutaneous tissue disorders

2 (4%)

1 (2%)

3 (6%)

Vascular disorders

1 (2%)

1 (2%)

2 (4%)

Ear and labyrinth disorders

1 (2%)

1 (2%)

No Declared AE

1 (2%)

1 (2%)