Note: This one actually has more functionality than can work across different sections for our life sciences project.

ae <- read.csv("data/ae.csv")
dm <- read.csv("data/dm.csv")

big_n_df <- dm %>%
  filter(ARMCD == "BLINDED") %>% 
  select(USUBJID, ARMCD) %>% 
  distinct()
ae_trt <- ae %>% 
  filter(EPOCH == "TREATMENT") %>% 
  sample_n(20) %>% 
  identity()
  
ae_dm_df <- dm %>%  
  select(USUBJID, ARMCD) %>% 
  left_join(ae, by = "USUBJID") %>% 
  filter(ARMCD == "BLINDED") 

events & subjects

tplyr_table(ae_trt, AESEV) %>% 
  set_pop_data(ae_dm_df) %>%
  # set_pop_treat_var(TRT01A) %>%
  add_layer(
    group_count(vars(AESOC, AEDECOD)) %>% 
      set_distinct_by(USUBJID) %>% 
      # set_format_strings(f_str('xx (xx.x%)', distinct_n, distinct_pct))
      set_format_strings(f_str('xx (xx.x%) [xxx]', distinct_n, distinct_pct, n))
  ) %>% 
  add_total_group(group_name = "Total") %>% 
  build() %>% 
  select(-contains("ord")) %>% 
  select(-any_of(c("var1_"))) %>% 
  # head() %>% 
  rename_with(., ~ gsub("var1_", "", .x)) %>% 
  rename(SOC = row_label1, PT = row_label2) %>% 
  gt::gt()
SOC PT MILD MODERATE SEVERE Total
10007541 10007541 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10007541 Ventricular extrasystoles 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10013993 10013993 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10013993 Tinnitus 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10017947 10017947 3 ( 2.5%) [ 3] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 3 ( 1.3%) [ 3]
10017947 Abdominal distension 1 ( 0.8%) [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%) [ 1]
10029205 Taste disorder 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10037175 10037175 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10037175 Nervousness 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10038738 10038738 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10038738 Nasal discomfort 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10040785 10040785 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10040785 Erythema 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10047065 10047065 2 ( 1.7%) [ 2] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 2 ( 0.9%) [ 2]
10047065 Hypotension 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
10047065 Orthostatic hypotension 1 ( 0.8%) [ 1] 0 ( 0.0%) [ 0] 0 ( 0.0%) [ 0] 1 ( 0.4%) [ 1]
  # kable()
# pop_data = big_n_df %>% 
#   tplyr_table(
#     target = ae_trt, 
#     treat_var = AESOC) %>% 
#   add_layer(
#     group_count()
#   ) %>% 
#   add_total_group(table, group_name = "Total")
#   build()

Descriptives

Shift tables