From 3148bd5704eae4581cfd366d5dc7edc9a09b69e4 Mon Sep 17 00:00:00 2001 From: b_falquet <64274616+BFalquet@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:00:04 +0100 Subject: [PATCH] 108 VST01 and EGT01 (#109) new tables Co-authored-by: benoit --- NAMESPACE | 4 + R/egt01.R | 127 +++++++++++++++++++++++++++++++ R/standard_data_preprocessing.R | 28 ++++++- R/utils.R | 5 ++ R/vst01.R | 129 ++++++++++++++++++++++++++++++++ _pkgdown.yaml | 4 + inst/WORDLIST | 2 + man/egt01_1.Rd | 86 +++++++++++++++++++++ man/filter_adeg_anl01fl.Rd | 14 ++++ man/filter_advs_anl01fl.Rd | 14 ++++ man/vst01_1.Rd | 87 +++++++++++++++++++++ 11 files changed, 499 insertions(+), 1 deletion(-) create mode 100644 R/egt01.R create mode 100644 R/vst01.R create mode 100644 man/egt01_1.Rd create mode 100644 man/filter_adeg_anl01fl.Rd create mode 100644 man/filter_advs_anl01fl.Rd create mode 100644 man/vst01_1.Rd diff --git a/NAMESPACE b/NAMESPACE index 4ca380d31..c2ca2d59c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/egt01.R b/R/egt01.R new file mode 100644 index 000000000..0fefea494 --- /dev/null +++ b/R/egt01.R @@ -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), " ")) +} diff --git a/R/standard_data_preprocessing.R b/R/standard_data_preprocessing.R index a50dfaaa5..9ca8b2ac2 100644 --- a/R/standard_data_preprocessing.R +++ b/R/standard_data_preprocessing.R @@ -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 @@ -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 diff --git a/R/utils.R b/R/utils.R index bfd584cf1..08027b995 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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 } diff --git a/R/vst01.R b/R/vst01.R new file mode 100644 index 000000000..56e91178c --- /dev/null +++ b/R/vst01.R @@ -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)) +} diff --git a/_pkgdown.yaml b/_pkgdown.yaml index aa395bf13..306631bbe 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -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: @@ -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 diff --git a/inst/WORDLIST b/inst/WORDLIST index 01744a187..880ee6189 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -16,6 +16,7 @@ CTACAE CTCAE DMT EORTC +EGT GDSR LBT NCI @@ -45,3 +46,4 @@ templating tlg tlgfunction tlgs +VST diff --git a/man/egt01_1.Rd b/man/egt01_1.Rd new file mode 100644 index 000000000..9165bb1b1 --- /dev/null +++ b/man/egt01_1.Rd @@ -0,0 +1,86 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/egt01.R +\name{egt01_1} +\alias{egt01_1} +\alias{egt01_1_lyt} +\title{EGT01 Table 1 (Default) ECG Assessments and Change from Baseline by Visit Table 1} +\usage{ +egt01_1( + adam_db, + armvar = .study$armvar, + summaryvars = .study$evo_vars, + summaryvars_lbls = var_labels_for(adam_db$adeg, summaryvars), + visitvar = "AVISIT", + prune_0 = TRUE, + deco = std_deco("EGT01"), + .study = list(armvar = "ACTARM", evo_vars = c("AVAL", "CHG")) +) + +egt01_1_lyt( + 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") +) +} +\arguments{ +\item{adam_db}{(\code{dm}) object containing the ADaM datasets} + +\item{armvar}{(\code{character}) variable used for column splitting} + +\item{summaryvars}{(\verb{vector of string}) the variables to be analyzed. For this table, \code{AVAL} and \code{CHG} by default.} + +\item{summaryvars_lbls}{(\verb{vector of string}) the label of the variables to be analyzed.} + +\item{visitvar}{(\code{string}) typically one of \code{"AVISIT"} (Default) or \code{"ATPTN"} depending on the type of time point to +be displayed.} + +\item{prune_0}{(\code{logical}) remove 0 count rows} + +\item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} + +\item{.study}{(\code{list}) with default values for the arguments of the function} + +\item{lbl_AVISIT}{(\code{string}) label of the \code{visitvar} variable.} + +\item{lbl_PARAM}{(\code{string}) label of the \code{PARAM} variable.} +} +\value{ + +} +\description{ +The \code{EGT01} table 1 summarizes several electrocardiogram parameters and their evolution throughout the study. +} +\details{ +\itemize{ +\item The \verb{Analysis Value} column, displays the number of patients, the mean, standard deviation, median and range of +the analysis value for each visit. +\item The \verb{Change from Baseline} column, displays the number of patient and the mean, standard deviation, +median and range of changes relative to the baseline. +\item Remove zero-count rows unless overridden with \code{prune_0 = FALSE}. +\item Split columns by arm, typically \code{ACTARM}. +\item Does not include a total column by default. +\item Sorted based on factor level; first by \code{PARAM} labels in alphabetic order then by chronological time point given +by \code{AVISIT}. Re-level to customize order +} +} +\section{Functions}{ +\itemize{ +\item \code{egt01_1_lyt}: +}} + +\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")) + +} diff --git a/man/filter_adeg_anl01fl.Rd b/man/filter_adeg_anl01fl.Rd new file mode 100644 index 000000000..c80f684f7 --- /dev/null +++ b/man/filter_adeg_anl01fl.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standard_data_preprocessing.R +\name{filter_adeg_anl01fl} +\alias{filter_adeg_anl01fl} +\title{Filter \code{adeg} for \code{ANL01FL}} +\usage{ +filter_adeg_anl01fl(adam_db) +} +\arguments{ +\item{adam_db}{(\code{dm}) object containing the ADaM datasets} +} +\description{ +Filter \code{adeg} for \code{ANL01FL} +} diff --git a/man/filter_advs_anl01fl.Rd b/man/filter_advs_anl01fl.Rd new file mode 100644 index 000000000..7fbb83c7d --- /dev/null +++ b/man/filter_advs_anl01fl.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/standard_data_preprocessing.R +\name{filter_advs_anl01fl} +\alias{filter_advs_anl01fl} +\title{Filter \code{advs} for \code{ANL01FL}} +\usage{ +filter_advs_anl01fl(adam_db) +} +\arguments{ +\item{adam_db}{(\code{dm}) object containing the ADaM datasets} +} +\description{ +Filter \code{advs} for \code{ANL01FL} +} diff --git a/man/vst01_1.Rd b/man/vst01_1.Rd new file mode 100644 index 000000000..3db6957f8 --- /dev/null +++ b/man/vst01_1.Rd @@ -0,0 +1,87 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/vst01.R +\name{vst01_1} +\alias{vst01_1} +\alias{vst01_1_lyt} +\title{VST01 Table 1 (Default) Vital Sign Results and change from Baseline By Visit Table 1} +\usage{ +vst01_1( + adam_db, + armvar = .study$armvar, + summaryvars = .study$evo_vars, + summaryvars_lbls = var_labels_for(adam_db$advs, summaryvars), + visitvar = "AVISIT", + prune_0 = TRUE, + deco = std_deco("VST01"), + .study = list(armvar = "ACTARM", evo_vars = c("AVAL", "CHG")) +) + +vst01_1_lyt( + 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") +) +} +\arguments{ +\item{adam_db}{(\code{dm}) object containing the ADaM datasets} + +\item{armvar}{(\code{character}) variable used for column splitting} + +\item{summaryvars}{(\verb{vector of string}) the variables to be analyzed. For this table, \code{AVAL} and \code{CHG} by default.} + +\item{summaryvars_lbls}{(\verb{vector of string}) the label of the variables to be analyzed.} + +\item{visitvar}{(\code{string}) typically one of \code{"AVISIT"} (Default) or \code{"ATPTN"} depending on the type of time point to +be displayed.} + +\item{prune_0}{(\code{logical}) remove 0 count rows} + +\item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} + +\item{.study}{(\code{list}) with default values for the arguments of the function} + +\item{lbl_AVISIT}{(\code{string}) label of the \code{visitvar} variable.} + +\item{lbl_PARAM}{(\code{string}) label of the \code{PARAM} variable.} +} +\value{ + +} +\description{ +The \code{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. +} +\details{ +\itemize{ +\item The \verb{Analysis Value} column, displays the number of patients, the mean, standard deviation, median and range of +the analysis value for each visit. +\item The \verb{Change from Baseline} column, displays the number of patient and the mean, standard deviation, +median and range of changes relative to the baseline. +\item Remove zero-count rows unless overridden with \code{prune_0 = FALSE}. +\item Split columns by arm, typically \code{ACTARM}. +\item Does not include a total column by default. +\item Sorted based on factor level; first by \code{PARAM} labels in alphabetic order then by chronological time point given +by \code{AVISIT}. Re-level to customize order +} +} +\section{Functions}{ +\itemize{ +\item \code{vst01_1_lyt}: +}} + +\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")) + +}