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

Add lbt07 #366

Merged
merged 11 commits into from
Feb 3, 2023
1 change: 1 addition & 0 deletions DESCRIPTION
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Collate:
'lbt01.R'
'lbt04.R'
'lbt05.R'
'lbt07.R'
'lbt14.R'
'mht01.R'
'mng01.R'
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export(lbt05_1_lyt)
export(lbt05_1_main)
export(lbt05_1_post)
export(lbt05_1_pre)
export(lbt07_1)
export(lbt07_1_lyt)
export(lbt07_1_main)
export(lbt07_1_post)
export(lbt07_1_pre)
export(lbt14_1)
export(lbt14_1_lyt)
export(lbt14_1_main)
Expand Down
194 changes: 194 additions & 0 deletions R/lbt07.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# lbt07_1 ----

#' @describeIn lbt07_1 Main TLG function
#'
#' @inheritParams gen_args
#' @param grade_var (`character`) `PARAM` and variables derived from the standard lab grade variable `ATOXGR`:
#' * A grade direction variable (`GRADE_DIR`) is required in order to obtain
#' the correct denominators when building the layout as it is used to define row splitting.
#' * A toxicity grade variable (e.g. `GRADE_ANL`) where all negative values from
#' `ATOXGR` are replaced by their absolute values.
#' @param lbl_grade_var (`character`) label of the variables in `grade_var`. If `NULL`, uses the label
#' attribute of the columns selected in `grade_var`.
#' @param ... not used.
#'
#' @details
#' * Split columns by arm, typically `ACTARM`.
#'
#' @note
#' * `adam_db` object must contain an `adlb` table with columns `"USUBJID"`, `"ATOXGR"`,
#' `"ONTRTFL"` and column specified by `armvar`.
#'
#' @export
#'
lbt07_1_main <- function(adam_db,
armvar = "ACTARM",
grade_var = c("PARAM", "GRADE_DIR", "GRADE_ANL"),
deco = std_deco("LBT07"),
lbl_grade_var = c("Parameter", "Direction of Abnormality", "Toxicity Grade"),
...) {

lbt07_1_check(adam_db, ...)

lbl_grade_var <- if (is.null(lbl_grade_var)) {
var_labels_for(adam_db$adlb, grade_var)
} else {
lbl_grade_var
}
map <- unique(adam_db$adlb[adam_db$adlb$GRADE_DIR != "ZERO", c("PARAM", "GRADE_DIR", "GRADE_ANL")]) %>%
lapply(as.character) %>%
as.data.frame() %>%
arrange(PARAM, desc(GRADE_DIR), GRADE_ANL)


lyt <- lbt07_1_lyt(
armvar = armvar,
grade_var = grade_var,
lbl_grade_var = lbl_grade_var,
deco = deco,
map = map,
... = ...
)

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

tbl
}

#' @describeIn lbt07_1 Layout
#'
#' @inheritParams gen_args
#'
#' @param lbl_param (`character`) label of the `PARAM` variable.
#' @param lbl_gradedir (`character`) label of the `GRADE_DIR` variable.
#' @param map (`data.frame`) mapping of `PARAM`s to directions of abnormality.
#' @param ... not used.
#'
#' @export
#'
lbt07_1_lyt <- function(armvar,
lbl_gradedir,
lbl_param,
grade_var,
lbl_grade_var,
deco,
map,
...) {
names(lbl_grade_var) <- grade_var

basic_table_deco(deco, show_colcount = TRUE) %>%
split_cols_by(armvar) %>%
split_rows_by(
"PARAM",
label_pos = "topleft",
split_label = lbl_grade_var[1]
) %>%
summarize_num_patients(
var = "USUBJID",
required = "ATOXGR",
.stats = "unique_count"
) %>%
split_rows_by(
"GRADE_DIR",
label_pos = "topleft",
split_label = lbl_grade_var[2],
split_fun = trim_levels_to_map(map)
) %>%
count_abnormal_by_worst_grade(
var = "GRADE_ANL",
variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR"),
.formats = list(count_fraction = tern::format_count_fraction_fixed_dp),
.indent_mods = 4L
) %>%
append_topleft(" Highest NCI CTCAE Grade")
}

#' @describeIn lbt07_1 Preprocessing
#'
#' @inheritParams gen_args
#' @param ... not used.
#'
#' @export
#'
lbt07_1_pre <- function(adam_db, ...) {
checkmate::assert_class(adam_db, "dm")

db <- adam_db %>%
dm_zoom_to("adlb") %>%
filter(
.data$ATOXGR != "<Missing>",
.data$ONTRTFL == "Y"
) %>%
mutate(
GRADE_DIR = factor(
case_when(
ATOXGR %in% c("-1", "-2", "-3", "-4") ~ "LOW",
ATOXGR == "0" ~ "ZERO",
ATOXGR %in% c("1", "2", "3", "4") ~ "HIGH"
),
levels = c("LOW", "ZERO", "HIGH")
),
GRADE_ANL = fct_relevel(
forcats::fct_recode(ATOXGR,
`1` = "-1", `2` = "-2", `3` = "-3", `4` = "-4"
),
c("0", "1", "2", "3", "4")
),
PARAM = as.factor(.data$PARAM)
) %>%
dm_update_zoomed()
}

#' @describeIn lbt07_1 Checks
#'
#' @inheritParams gen_args
#' @param ... not used.
#'
lbt07_1_check <- function(adam_db,
req_tables = c("adsl", "adlb"),
armvar = "ACTARM",
...) {
assert_all_tablenames(adam_db, req_tables)

msg <- NULL

adlb_layout_col <- c("USUBJID", "ATOXGR", "ONTRTFL")
adsl_layout_col <- c("USUBJID")

msg <- c(msg, check_all_colnames(adam_db$adlb, c(armvar, adlb_layout_col)))
msg <- c(msg, check_all_colnames(adam_db$adsl, c(adsl_layout_col)))

if (is.null(msg)) {
TRUE
} else {
stop(paste(msg, collapse = "\n "))
}
}


#' @describeIn lbt07_1 Postprocessing
#'
#' @inheritParams gen_args
#' @param ... not used.
#'
#' @export
#'
lbt07_1_post <- function(tlg, prune_0 = TRUE, ...) {
std_postprocess(tlg)
}

#' `LBT07` Table 1 (Default) Laboratory Test Results and Change from Baseline by Visit.
#'
#' The `LBT07` table provides an
#' overview of the analysis values and its change from baseline of each respective arm over the course of the trial.
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' run(lbt07_1, syn_data)
lbt07_1 <- chevron_t(
main = lbt07_1_main,
preprocess = lbt07_1_pre,
postprocess = lbt07_1_post,
adam_datasets = c("adlb", "adsl")
)
1 change: 1 addition & 0 deletions _pkgdown.yaml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ reference:
- lbt01_1
- lbt04_1
- lbt05_1
- lbt07_1
- lbt14_1
- lbt14_2
- mht01_1
Expand Down
107 changes: 107 additions & 0 deletions man/lbt07_1.Rd

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

44 changes: 44 additions & 0 deletions tests/testthat/_snaps/default_tlg.md
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,55 @@
Last or replicated 3 (2.4%) 9 (6.9%) 5 (4.0%)
Any Abnormality 4 (3.1%) 9 (6.9%) 6 (4.8%)

# lbt07_1 functions with default argument value return expected result with test data
# lbt14_1 functions with default argument value return expected result with test data

Code
res
Output
Parameter
Direction of Abnormality A: Drug X B: Placebo C: Combination
Highest NCI CTCAE Grade (N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————
Alanine Aminotransferase Measurement (n) 134 134 132
LOW
1 25 (18.7%) 22 (16.4%) 28 (21.2%)
2 24 (17.9%) 22 (16.4%) 21 (15.9%)
3 24 (17.9%) 20 (14.9%) 21 (15.9%)
4 13 (9.7%) 10 (7.5%) 11 (8.3%)
Any 68 (50.7%) 62 (46.3%) 61 (46.2%)
HIGH
1 23 (17.2%) 25 (18.7%) 27 (20.5%)
2 22 (16.4%) 24 (17.9%) 24 (18.2%)
3 18 (13.4%) 25 (18.7%) 23 (17.4%)
4 16 (11.9%) 15 (11.2%) 16 (12.1%)
Any 70 (52.2%) 70 (52.2%) 76 (57.6%)
C-Reactive Protein Measurement (n) 134 134 132
LOW
1 32 (23.9%) 33 (24.6%) 22 (16.7%)
2 34 (25.4%) 16 (11.9%) 22 (16.7%)
3 18 (13.4%) 15 (11.2%) 22 (16.7%)
4 14 (10.4%) 15 (11.2%) 12 (9.1%)
Any 78 (58.2%) 63 (47.0%) 69 (52.3%)
HIGH
1 29 (21.6%) 29 (21.6%) 23 (17.4%)
2 26 (19.4%) 26 (19.4%) 25 (18.9%)
3 23 (17.2%) 17 (12.7%) 19 (14.4%)
4 19 (14.2%) 20 (14.9%) 22 (16.7%)
Any 79 (59.0%) 71 (53.0%) 76 (57.6%)
Immunoglobulin A Measurement (n) 134 134 132
LOW
1 30 (22.4%) 34 (25.4%) 28 (21.2%)
2 17 (12.7%) 25 (18.7%) 22 (16.7%)
3 22 (16.4%) 16 (11.9%) 23 (17.4%)
4 11 (8.2%) 21 (15.7%) 14 (10.6%)
Any 73 (54.5%) 80 (59.7%) 70 (53.0%)
HIGH
1 31 (23.1%) 24 (17.9%) 25 (18.9%)
2 23 (17.2%) 27 (20.1%) 23 (17.4%)
3 19 (14.2%) 16 (11.9%) 24 (18.2%)
4 16 (11.9%) 15 (11.2%) 6 (4.5%)
Any 75 (56.0%) 71 (53.0%) 64 (48.5%)
LBT14 - Low Direction


Expand Down
Loading