Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Review #140 #221

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export(aet04_1)
export(aet04_1_lyt)
export(aet04_1_main)
export(aet04_1_pre)
export(aet04_2)
export(aet04_2_lyt)
export(aet04_2_main)
export(aet04_2_pre)
export(assert_all_tablenames)
export(assert_colnames)
export(assert_one_tablenames)
Expand Down
13 changes: 8 additions & 5 deletions R/aet03.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ aet03_1_main <- function(adam_db,
)) {
# specific to AET03: avoid error if some severity levels are not present
# TODO: rename all gradation to grade or grading (depending on context)
severity_grade <- levels(adam_db$adae[["AESEV"]])
severity_grade <- levels(adam_db$adae[["ASEV"]])

lyt <- aet03_1_lyt(
armvar = armvar,
Expand Down Expand Up @@ -104,7 +104,8 @@ aet03_1_lyt <- function(armvar = .study$actualarm,
add_colcounts() %>%
ifneeded_add_overall_col(lbl_overall) %>%
summarize_occurrences_by_grade(
var = "AESEV",
var = "ASEV",
.indent_mods = 11L,
grade_groups = list("- Any Intensity -" = severity_grade)
) %>%
split_rows_by(
Expand All @@ -117,7 +118,8 @@ aet03_1_lyt <- function(armvar = .study$actualarm,
split_label = lbl_aebodsys
) %>%
summarize_occurrences_by_grade(
var = "AESEV",
var = "ASEV",
.indent_mods = 10L,
grade_groups = list("- Any Intensity -" = severity_grade)
) %>%
split_rows_by(
Expand All @@ -130,7 +132,8 @@ aet03_1_lyt <- function(armvar = .study$actualarm,
split_label = lbl_aedecod
) %>%
summarize_occurrences_by_grade(
var = "AESEV",
var = "ASEV",
.indent_mods = 8L,
grade_groups = list("- Any Intensity -" = severity_grade)
)
}
Expand All @@ -149,7 +152,7 @@ aet03_1_pre <- function(adam_db, ...) {

adam_db %>%
dm_zoom_to("adae") %>%
filter(.data$ANL01FL == "Y") %>%
filter(.data$ANL01FL == "Y", .data$ASEV != c("", NA)) %>%
dm_update_zoomed()
}

Expand Down
201 changes: 194 additions & 7 deletions R/aet04.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ aet04_1_lyt <- function(armvar = .study$actualarm,
add_colcounts() %>%
ifneeded_add_overall_col(lbl_overall) %>%
summarize_occurrences_by_grade(
var = "AETOXGR",
.indent_mods = 11L,
var = "ATOXGR",
grade_groups = group_grades
) %>%
split_rows_by(
Expand All @@ -138,9 +139,9 @@ aet04_1_lyt <- function(armvar = .study$actualarm,
split_label = lbl_aebodsys
) %>%
summarize_occurrences_by_grade(
var = "AETOXGR",
var = "ATOXGR",
grade_groups = group_grades,
.indent_mods = 0L
.indent_mods = 10L
) %>%
split_rows_by(
"AEDECOD",
Expand All @@ -154,12 +155,12 @@ aet04_1_lyt <- function(armvar = .study$actualarm,
summarize_num_patients(
var = "USUBJID",
.stats = "unique",
.labels = "Any Grade"
.labels = " Any Grade"
) %>%
count_occurrences_by_grade(
var = "AETOXGR",
var = "ATOXGR",
grade_groups = group_grades[-1],
.indent_mods = -1L
.indent_mods = 8L
)
}

Expand All @@ -177,7 +178,7 @@ aet04_1_pre <- function(adam_db, ...) {

adam_db %>%
dm_zoom_to("adae") %>%
filter(.data$ANL01FL == "Y") %>%
filter(.data$ANL01FL == "Y", .data$ATOXGR != c("", NA)) %>%
dm_update_zoomed()
}

Expand All @@ -189,3 +190,189 @@ aet04_1_pre <- function(adam_db, ...) {
#' @include chevron_tlg-S4class.R
#' @export
aet04_1 <- chevron_tlg(aet04_1_main, aet04_1_pre, adam_datasets = c("adsl", "adae"))



#' @describeIn aet04_2 Main TLG function
#'
#' @inheritParams gen_args
#' @param group_grades (`list`) putting in correspondence severity levels and labels.
#'
#' @details
#' * Numbers represent absolute numbers of patients and fraction of `N`, or absolute number of event when specified.
#' * Remove zero-count rows unless overridden with `prune_0 = FALSE`.
#' * Split columns by arm, typically `ACTARM`.
#' * Does not include a total column by default.
#' * Sort Body System or Organ Class and Dictionary-Derived Term by highest overall frequencies. Analysis Toxicity
#' Grade is sorted by severity.
#'
#' @export
#'
#' @examples
#' library(dm)
#'
#' db <- syn_test_data() %>%
#' aet04_2_pre()
#'
#' aet04_2_main(db)
#'
aet04_2_main <- function(adam_db,
armvar = .study$actualarm,
group_grades = .study$group_grades,
lbl_overall = .study$lbl_overall,
prune_0 = TRUE,
deco = std_deco("AET04"),
.study = list(
actualarm = "ACTARM",
lbl_overall = NULL,
group_grades = NULL
)) {
lbl_aebodsys <- var_labels_for(adam_db$adae, "AEBODSYS")
lbl_aedecod <- var_labels_for(adam_db$adae, "AEDECOD")

# TODO: check that there are not grades in the data that are not defined in the `group_grades` map
if (is.null(group_grades)) {
group_grades <- list(
"Any Grade" = c("1", "2", "3", "4", "5"),
"Grade 1-2" = c("1", "2"),
"Grade 3-5" = c("3", "4", "5")
)
}

lyt <- aet04_2_lyt(
armvar = armvar,
lbl_overall = lbl_overall,
lbl_aebodsys = lbl_aebodsys,
lbl_aedecod = lbl_aedecod,
group_grades = group_grades,
deco = deco
)

tbl <- build_table(
lyt,
df = adam_db$adae,
alt_counts_df = adam_db$adsl
)

if (prune_0) tbl <- tbl %>% trim_rows()

tbl_sorted <- tbl %>%
sort_at_path(
path = c("AEBODSYS"),
scorefun = cont_n_allcols
) %>%
sort_at_path(
path = c("AEBODSYS", "*", "AEDECOD"),
scorefun = cont_n_allcols
)

tbl_sorted
}

#' @describeIn aet04_2 Layout
#'
#' @inheritParams gen_args
#'
#' @param lbl_aebodsys (`character`) text label for `AEBODSYS`.
#' @param lbl_aedecod (`character`) text label for `AEDECOD`.
#' @param group_grades (`list`) putting in correspondence severity levels and labels.
#'
#' @export
#'
#' @examples
#' aet04_2_lyt(armvar = "ACTARM")
aet04_2_lyt <- function(armvar = .study$actualarm,
lbl_aebodsys = "AEBODSYS",
lbl_aedecod = "AEDECOD",
group_grades = .study$group_grades,
lbl_overall = .study$lbl_overall,
deco = std_deco("AET04"),
.study = list(
actualarm = "ACTARM",
lbl_overall = NULL,
group_grades = NULL
)) {
if (is.null(group_grades)) {
group_grades <- list(
"Any Grade" = c("1", "2", "3", "4", "5"),
"Grade 1-2" = c("1", "2"),
"Grade 3-5" = c("3", "4", "5")
)
}

basic_table_deco(deco) %>%
split_cols_by(var = armvar) %>%
add_colcounts() %>%
ifneeded_add_overall_col(lbl_overall) %>%
summarize_occurrences_by_grade(
.indent_mods = 11L,
var = "ATOXGR",
grade_groups = group_grades
) %>%
split_rows_by(
"AEBODSYS",
child_labels = "visible",
nested = FALSE,
indent_mod = -1L,
split_fun = drop_split_levels,
label_pos = "topleft",
split_label = lbl_aebodsys
) %>%
summarize_occurrences_by_grade(
var = "ATOXGR",
grade_groups = group_grades,
.indent_mods = 10L
) %>%
split_rows_by(
"AEDECOD",
child_labels = "visible",
nested = TRUE,
indent_mod = -1L,
split_fun = drop_split_levels,
label_pos = "topleft",
split_label = lbl_aedecod
) %>%
summarize_num_patients(
var = "USUBJID",
.stats = "unique",
.labels = " Any Grade"
) %>%
count_occurrences_by_grade(
var = "ATOXGR",
grade_groups = group_grades[-1],
.indent_mods = 8L
)
}



#' @describeIn aet04_2 Preprocessing
#'
#' @inheritParams gen_args
#' @param ... not used.
#'
#' @export
#'
#' @examples
#' syn_test_data() %>%
#' aet04_2_pre()
aet04_2_pre <- function(adam_db, ...) {
checkmate::assert_class(adam_db, "dm")

adam_db %>%
dm_zoom_to("adae") %>%
filter(.data$ANL01FL == "Y", .data$ATOXGR != c("", NA)) %>%
dm_update_zoomed()
}

# `AET04_2` Pipeline ----

#' `AET04` Table 2 (Supplementary) Adverse Events by Highest `NCI` `CTACAE` `AE` Grade with Analysis Toxicity Grade 3-5
#' combined.
#'
#' The `AET04_2` table provides an overview of adverse event with the highest `NCI` `CTCAE` grade per individual,
#' with the Analysis Toxicity Grade 3-5 combined in one group.
#'
#' @include chevron_tlg-S4class.R
#' @export
aet04_2 <- chevron_tlg(aet04_2_main, aet04_2_pre, adam_datasets = c("adsl", "adae"))
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ reference:
- aet02_3
- aet03_1
- aet04_1
- aet04_2
- cmt01a_1
- cmt01a_2
- cmt01a_3
Expand Down
95 changes: 95 additions & 0 deletions man/aet04_2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.