library(junco)
library(rtables)
library(dplyr)
# Create sample table layout
colspan_trt_map <- create_colspan_map(adsl,
non_active_grp = "Placebo",
non_active_grp_span_lbl = " ",
active_grp_span_lbl = "Active Study Agent",
colspan_var = "colspan_trt",
trt_var = "TRT01A")
lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") |>
split_cols_by("colspan_trt", split_fun = trim_levels_to_map(map = colspan_trt_map)) |>
split_cols_by("TRT01A", show_colcounts = FALSE) |>
split_rows_by("SEX", section_div = " ", split_fun = drop_split_levels) |>
summarize_row_groups("SEX", cfun = a_freq_j, extra_args = list(denom = "n_df", denom_by = "SEX", riskdiff = FALSE, extrablankline = TRUE, .stats = c("count_unique"))) |>
analyze("RESPONSE", afun = a_freq_j, extra_args = list(denom = "n_df", denom_by = "SEX", riskdiff = FALSE, .stats = c("count_unique_fraction")))
result <- build_table(lyt, adsl)
export_TLG_as_docx(result, tblid = "example_table")