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)
#> Warning: Unknown or uninitialised column: `grade`.
#> Error in ae_table_soc(df_ae = ae, df_enrol = enrolres): Grade ("AEGR") should be a numeric column.
ae_table_soc(df_ae=ae, df_enrol=enrolres, arm="arm")
#> Warning: Unknown or uninitialised column: `grade`.
#> Error in ae_table_soc(df_ae = ae, df_enrol = enrolres, arm = "arm"): Grade ("AEGR") should be a numeric column.

#sub population
ae_table_soc(df_ae=ae, df_enrol=head(enrolres, 10), arm="arm")
#> Warning: Unknown or uninitialised column: `grade`.
#> Error in ae_table_soc(df_ae = ae, df_enrol = head(enrolres, 10), arm = "arm"): Grade ("AEGR") should be a numeric column.

#the resulting flextable can be customized using the flextable package
ae_table_soc(ae, df_enrol=enrolres, total=FALSE) %>%
  as_flextable() %>%
  hline(i=~soc=="" & soc!=dplyr::lead(soc))
#> Error in hline(., i = ~soc == "" & soc != dplyr::lead(soc)): could not find function "hline"
ae_table_soc(ae, df_enrol=enrolres, term=NULL, sort_by_count=FALSE) %>%
  as_flextable() %>%
  bold(i=~soc=="Eye disorders")
#> Error in bold(., i = ~soc == "Eye disorders"): could not find function "bold"
ae_table_soc(ae, df_enrol=enrolres, term=NULL, arm=NULL) %>%
  as_flextable() %>%
  highlight(i=~soc=="Hepatobiliary disorders", j="all_patients_Tot")
#> Error in highlight(., i = ~soc == "Hepatobiliary disorders", j = "all_patients_Tot"): could not find function "highlight"