Skip to content

Commit

Permalink
108 VST01 and EGT01 (#109)
Browse files Browse the repository at this point in the history
new tables

Co-authored-by: benoit <benoit.falquet@roche.com>
  • Loading branch information
BFalquet and benoit committed Dec 16, 2021
1 parent 356b281 commit 3148bd5
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export(dst01_2)
export(dst01_2_lyt)
export(dst01_3)
export(dst01_3_lyt)
export(egt01_1)
export(egt01_1_lyt)
export(ext01_1)
export(ext01_1_lyt)
export(ext01_2)
Expand All @@ -40,6 +42,8 @@ export(std_mutate_fun)
export(std_pmap)
export(syn_test_data)
export(var_labels_for)
export(vst01_1)
export(vst01_1_lyt)
import(dm)
import(dplyr)
import(rtables)
Expand Down
127 changes: 127 additions & 0 deletions R/egt01.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#' EGT01 Table 1 (Default) ECG Assessments and Change from Baseline by Visit Table 1
#'
#' The `EGT01` table 1 summarizes several electrocardiogram parameters and their evolution throughout the study.
#'
#' @inheritParams gen_args
#' @param summaryvars (`vector of string`) the variables to be analyzed. For this table, `AVAL` and `CHG` by default.
#' @param summaryvars_lbls (`vector of string`) the label of the variables to be analyzed.
#' @param visitvar (`string`) typically one of `"AVISIT"` (Default) or `"ATPTN"` depending on the type of time point to
#' be displayed
#'
#' @details
#' * The `Analysis Value` column, displays the number of patients, the mean, standard deviation, median and range of
#' the analysis value for each visit.
#' * The `Change from Baseline` column, displays the number of patient and the mean, standard deviation,
#' median and range of changes relative to the baseline.
#' * Remove zero-count rows unless overridden with `prune_0 = FALSE`.
#' * Split columns by arm, typically `ACTARM`.
#' * Does not include a total column by default.
#' * Sorted based on factor level; first by `PARAM` labels in alphabetic order then by chronological time point given
#' by `AVISIT`. Re-level to customize order
#'
#' @importFrom dplyr filter
#'
#' @export
#'
#' @examples
#' library(dm)
#'
#' db <- syn_test_data() %>%
#' preprocess_data("egt01_1")
#'
#' egt01_1(db)
#' egt01_1(db, summaryvars_lbls = c("Value at Visit", "Change from Baseline"))
#'
egt01_1 <- function(adam_db,
armvar = .study$armvar,
summaryvars = .study$evo_vars,
summaryvars_lbls = var_labels_for(adam_db$adeg, summaryvars),
visitvar = "AVISIT", # or ATPTN
prune_0 = TRUE,
deco = std_deco("EGT01"),
.study = list(
armvar = "ACTARM",
evo_vars = c("AVAL", "CHG")
)) {

lbl_AVISIT <- var_labels_for(adam_db$adeg, visitvar)
lbl_PARAM <- var_labels_for(adam_db$adeg, "PARAM")

lyt <- egt01_1_lyt(
armvar = armvar,
summaryvars = summaryvars,
summaryvars_lbls = summaryvars_lbls,
visitvar = visitvar,
lbl_AVISIT = lbl_AVISIT,
lbl_PARAM = lbl_PARAM,
deco = deco
)

tbl <- build_table(
lyt,
df = adam_db$adeg
)

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

tbl

}

#' EGT01 Layout 1 (Default)
#'
#' @describeIn egt01_1
#'
#' @inheritParams gen_args
#'
#' @param summaryvars (`vector of string`) the variables to be analyzed. For this table, `AVAL` and `CHG` by default.
#' @param summaryvars_lbls (`vector of string`) the label of the variables to be analyzed.
#' @param visitvar (`string`) typically one of `"AVISIT"` (Default) or `"ATPTN"` depending on the type of time point to
#' be displayed.
#' @param lbl_AVISIT (`string`) label of the `visitvar` variable.
#' @param lbl_PARAM (`string`) label of the `PARAM` variable.
#'
#' @return
#' @export
egt01_1_lyt <- function(armvar = .study$armvar,
summaryvars = .study$evo_vars,
summaryvars_lbls = .study$evo_vars_lbls,
visitvar = .study$visitvar,
lbl_AVISIT = "",
lbl_PARAM = "",
deco = std_deco("EGT01"),
.study = list(
armvar = "ACTARM",
evo_vars = c("AVAL", "CHG"),
evo_vars_lbls = c("Analysis \nValue", "Change from \nBaseline"),
visitvar = "AVISIT"
)
) {


# TODE solve the problem of the overall column
# remove change from baseline in BASELINE

basic_table_deco(deco) %>%
split_cols_by(armvar) %>%
split_rows_by(
"PARAM",
split_fun = drop_split_levels,
label_pos = "hidden",
split_label = paste(lbl_PARAM)
) %>%
split_rows_by(
visitvar,
split_fun = drop_split_levels,
label_pos = "hidden",
split_label = lbl_AVISIT
) %>%
split_cols_by_multivar(
vars = summaryvars,
varlabels = summaryvars_lbls,
nested = TRUE
) %>%
summarize_colvars() %>%
append_topleft(paste(lbl_PARAM)) %>%
append_topleft(c(paste(" ", lbl_AVISIT), " "))
}
28 changes: 27 additions & 1 deletion R/standard_data_preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ std_preprocessing_map <- tibble::tribble(
"dst01_1", NA, NA, c("adsl"),
"dst01_2", NA, "mutate_adsl_gp", c("adsl"),
"dst01_3", NA, "mutate_adsl_gp", c("adsl"),
"egt01_1", "filter_adeg_anl01fl", NA, c("adsl", "adeg"),
"ext01_1", "filter_adex_drug", "reorder_adex_params", c("adsl", "adex"),
"ext01_2", "filter_adex_drug", "remove_adex_aval", c("adsl", "adex"),
"lbt01_1", "filter_adlb_anl01fl", NA, c("adsl", "adlb")
"lbt01_1", "filter_adlb_anl01fl", NA, c("adsl", "adlb"),
"vst01_1", "filter_advs_anl01fl", NA, c("adsl", "advs")
)

#' Standard Preprocessing Map
Expand Down Expand Up @@ -217,6 +219,30 @@ filter_adlb_anl01fl <- function(adam_db) {
dm_apply_filters()
}

#' Filter `adeg` for `ANL01FL`
#'
#' @inheritParams gen_args
#'
filter_adeg_anl01fl <- function(adam_db) {
assert_that(is(adam_db, "dm"))

adam_db %>%
dm_filter(adeg, bol_YN(ANL01FL)) %>%
dm_apply_filters()
}

#' Filter `advs` for `ANL01FL`
#'
#' @inheritParams gen_args
#'
filter_advs_anl01fl <- function(adam_db) {
assert_that(is(adam_db, "dm"))

adam_db %>%
dm_filter(advs, bol_YN(ANL01FL)) %>%
dm_apply_filters()
}

#' Filter `adex` for `PARCAT1`
#'
#' @inheritParams gen_args
Expand Down
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ syn_test_data <- function() {
mutate(ANL01FL = "Y") %>%
dm_update_zoomed()

db_m <- db %>%
dm_zoom_to(advs) %>%
mutate(ANL01FL = "Y") %>%
dm_update_zoomed()

db_m
}

Expand Down
129 changes: 129 additions & 0 deletions R/vst01.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#' VST01 Table 1 (Default) Vital Sign Results and change from Baseline By Visit Table 1
#'
#' The `VST01` table provides an overview of the Vital Sign values and its change from baseline of each respective arm
#' over the course of the trial.
#'
#' @inheritParams gen_args
#' @param summaryvars (`vector of string`) the variables to be analyzed. For this table, `AVAL` and `CHG` by default.
#' @param summaryvars_lbls (`vector of string`) the label of the variables to be analyzed.
#' @param visitvar (`string`) typically one of `"AVISIT"` (Default) or `"ATPTN"` depending on the type of time point to
#' be displayed
#'
#' @details
#' * The `Analysis Value` column, displays the number of patients, the mean, standard deviation, median and range of
#' the analysis value for each visit.
#' * The `Change from Baseline` column, displays the number of patient and the mean, standard deviation,
#' median and range of changes relative to the baseline.
#' * Remove zero-count rows unless overridden with `prune_0 = FALSE`.
#' * Split columns by arm, typically `ACTARM`.
#' * Does not include a total column by default.
#' * Sorted based on factor level; first by `PARAM` labels in alphabetic order then by chronological time point given
#' by `AVISIT`. Re-level to customize order
#'
#' @importFrom dplyr filter
#'
#' @export
#'
#' @examples
#' library(dm)
#'
#' db <- syn_test_data() %>%
#' preprocess_data("vst01_1")
#'
#' vst01_1(db)
#' vst01_1(db, summaryvars_lbls = c("Value at Visit", "Change from Baseline"))
#'
vst01_1 <- function(adam_db,
armvar = .study$armvar,
summaryvars = .study$evo_vars,
summaryvars_lbls = var_labels_for(adam_db$advs, summaryvars),
visitvar = "AVISIT", # or ATPTN
prune_0 = TRUE,
deco = std_deco("VST01"),
.study = list(
armvar = "ACTARM",
evo_vars = c("AVAL", "CHG")
)) {

lbl_AVISIT <- var_labels_for(adam_db$advs, visitvar)
lbl_PARAM <- var_labels_for(adam_db$advs, "PARAM")

lyt <- vst01_1_lyt(
armvar = armvar,
summaryvars = summaryvars,
summaryvars_lbls = summaryvars_lbls,
visitvar = visitvar,
lbl_AVISIT = lbl_AVISIT,
lbl_PARAM = lbl_PARAM,
deco = deco
)

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

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

tbl
}

#' LBT01 Layout 1 (Default)
#'
#' @describeIn vst01_1
#'
#' @inheritParams gen_args
#'
#' @param summaryvars (`vector of string`) the variables to be analyzed. For this table, `AVAL` and `CHG` by default.
#' @param summaryvars_lbls (`vector of string`) the label of the variables to be analyzed.
#' @param visitvar (`string`) typically one of `"AVISIT"` (Default) or `"ATPTN"` depending on the type of time point to
#' be displayed.
#' @param lbl_AVISIT (`string`) label of the `visitvar` variable.
#' @param lbl_PARAM (`string`) label of the `PARAM` variable.
#'
#' @return
#' @export
vst01_1_lyt <- function(armvar = .study$armvar,
summaryvars = .study$evo_vars,
summaryvars_lbls = .study$evo_vars_lbls,
visitvar = .study$visitvar,
lbl_AVISIT = "",
lbl_PARAM = "",
deco = std_deco("EGT01"),
.study = list(
armvar = "ACTARM",
evo_vars = c("AVAL", "CHG"),
evo_vars_lbls = c("Analysis \nValue", "Change from \nBaseline"),
visitvar = "AVISIT"
)
) {


# TODE solve the problem of the overall column
# remove change from baseline in BASELINE
# problem with the column count

basic_table_deco(deco) %>%
split_cols_by(armvar) %>%
split_rows_by(
"PARAM",
split_fun = drop_split_levels,
label_pos = "hidden",
split_label = paste(lbl_PARAM)
) %>%
split_rows_by(
visitvar,
split_fun = drop_split_levels,
label_pos = "hidden",
split_label = lbl_AVISIT
) %>%
split_cols_by_multivar(
vars = summaryvars,
varlabels = summaryvars_lbls,
nested = TRUE
) %>%
summarize_colvars() %>%
append_topleft(paste(lbl_PARAM)) %>%
append_topleft(paste(" ", lbl_AVISIT))
}
4 changes: 4 additions & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ reference:
- dst01_1
- dst01_2
- dst01_3
- egt01_1
- ext01_1
- ext01_2
- lbt01_1
- vst01_1

- title: Data Preprocess Functions
contents:
Expand All @@ -52,7 +54,9 @@ reference:
- std_mutate_fun
- filter_adex_drug
- filter_adae_anl01fl
- filter_adeg_anl01fl
- filter_adlb_anl01fl
- filter_advs_anl01fl
- mutate_adsl_gp
- remove_adex_aval
- reorder_adex_params
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CTACAE
CTCAE
DMT
EORTC
EGT
GDSR
LBT
NCI
Expand Down Expand Up @@ -45,3 +46,4 @@ templating
tlg
tlgfunction
tlgs
VST
Loading

0 comments on commit 3148bd5

Please sign in to comment.