From 138bbcddebc1c87ba13c1eb3ff56737f8727ac07 Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 07:26:51 +0000 Subject: [PATCH 01/32] Initial kmg01_1 --- DESCRIPTION | 1 + NAMESPACE | 3 + R/kmg01.R | 146 ++++++++++++++++++++++++++++++++++++ man/kmg01_1.Rd | 105 ++++++++++++++++++++++++++ tests/testthat/test-kmg01.R | 26 +++++++ 5 files changed, 281 insertions(+) create mode 100644 R/kmg01.R create mode 100644 man/kmg01_1.Rd create mode 100644 tests/testthat/test-kmg01.R diff --git a/DESCRIPTION b/DESCRIPTION index fd93762cfe..ba63a480b1 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -83,6 +83,7 @@ Collate: 'egt05_qtcat.R' 'ext01.R' 'gen_args.R' + 'kmg01.R' 'lbt01.R' 'lbt04.R' 'lbt05.R' diff --git a/NAMESPACE b/NAMESPACE index 0811c308f1..6075251d6f 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -148,6 +148,9 @@ export(get_preprocess) export(gg_list) export(grob_list) export(h_format_dec) +export(kmg01_1) +export(kmg01_1_main) +export(kmg01_1_pre) export(lbt01_1) export(lbt01_1_lyt) export(lbt01_1_main) diff --git a/R/kmg01.R b/R/kmg01.R new file mode 100644 index 0000000000..aa8073b9e9 --- /dev/null +++ b/R/kmg01.R @@ -0,0 +1,146 @@ +# kmg01_1 ---- + +#' @describeIn kmg01_1 Main TLG Function +#' +#' @details +#' * No overall value. +#' +#' @inheritParams gen_args +#' @param dataset (`string`) the name of a table in the `adam_db` object. +#' @param x_name (`string`) the name of the x-axis. +#' @param y_name (`string`) the name of the x-axis. +#' @param show_statis (`flag`) should the summary statistic table be displayed. +#' @param show_censor (`flag`) should the censor flag be displayed. +#' @param pval_method (`string`) should the censor flag be displayed. +#' @param ties (`string`) should the censor flag be displayed. +#' @param conf_level (`number`) should the censor flag be displayed. +#' @param legend_pos (`string`) the position of the legend. +#' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var` +#' with color names. +#' +#' @note +#' * `adam_db` object must contain the table specified by `dataset` with the columns specified by `arm_var`. +#' +#' @return a list of `ggplot` objects. +#' @export +kmg01_1_main <- function(adam_db, + dataset = "adtte", + arm_var = "ARMCD", + x_name = "Time (Days)", + y_name = "Survival Probability", + show_statis = TRUE, + show_censor = TRUE, + pval_method = "wald", + ties = "exact", + conf_level = 0.95, + legend_pos = "bottom", + position_coxph = c(0, 0.05), + position_surv_med = c(0.9, 0.9), + line_col = as.list(nestcolor::color_palette()), + ...) { + anl <- adam_db[[dataset]] + checkmate::assert_true(length(unique(anl$PARAMCD)) == 1) + checkmate::assert_character(x_name) + checkmate::assert_character(y_name) + checkmate::assert_flag(show_statis) + checkmate::assert_flag(show_censor) + + checkmate::assert_character(line_col, null.ok = TRUE) + + variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) + + ggtheme <- ggplot2::theme_bw() + + ggplot2::theme(legend.position = legend_pos) + + if (!is.null(names(line_col))) { + color_lvl <- sort(unique(df[[arm_var]])) + col <- line_col[as.character(color_lvl)] + + if (anyNA(col)) { + missing_col <- setdiff(color_lvl, names(col)) + stop(paste("Missing color matching for", toString(missing_col))) + } + + col <- unname(col) + } else { + col <- line_col + } + + gkm_plot <- if (!show_statis) { + g_km( + df = anl, + variables = variables, + censor_show = show_censor, + xlab = x_name, + ylab = y_name, + annot_surv_med = TRUE, + control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), + ggtheme = ggtheme, + position_coxph = position_coxph, + position_surv_med = position_surv_med + ) + } else { + g_km( + df = anl, + variables = variables, + censor_show = show_censor, + xlab = x_name, + ylab = y_name, + annot_coxph = TRUE, + control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), + ggtheme = ggtheme, + position_coxph = position_coxph, + position_surv_med = position_surv_med + ) + } + +} + +#' @describeIn kmg01_1 Preprocessing +#' +#' @inheritParams kmg01_1_main +#' +#' @export +kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { + checkmate::assert_class(adam_db, "dm") + + adam_db <- adam_db %>% + dm_zoom_to(!!dataset) %>% + filter(.data$PARAMCD == paramcd) %>% + mutate(is_event = CNSR == 0) %>% + dm_update_zoomed() +} + +#' @describeIn kmg01_1 Postprocessing +#' +#' @inheritParams gen_args +#' +kmg01_1_post <- function(tlg, ...) { + tlg +} + +# `kmg01_1` Pipeline ---- + +#' `KMG01` Kaplan-Meier Plot 1. +#' +#' +#' @include chevron_tlg-S4class.R +#' @export +#' +#' @examples +#' library(dm) +#' library(dplyr) +#' +#' col <- c( +#' "A: Drug X" = "black", +#' "B: Placebo" = "blue", +#' "C: Combination" = "gray" +#' ) +#' +#' run(kmg01_1, syn_data, dataset = "adtte", line_col = col) +kmg01_1 <- chevron_g( + main = kmg01_1_main, + preproces = kmg01_1_pre, + postprocess = kmg01_1_post, + adam_datasets = c("adsl", "adtte") +) diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd new file mode 100644 index 0000000000..e766ddb3dd --- /dev/null +++ b/man/kmg01_1.Rd @@ -0,0 +1,105 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kmg01.R +\docType{data} +\name{kmg01_1_main} +\alias{kmg01_1_main} +\alias{kmg01_1_pre} +\alias{kmg01_1_post} +\alias{kmg01_1} +\title{\code{KMG01} Kaplan-Meier Plot 1.} +\format{ +An object of class \code{chevron_g} of length 1. +} +\usage{ +kmg01_1_main( + adam_db, + dataset = "adtte", + arm_var = "ARMCD", + x_name = "Time (Days)", + y_name = "Survival Probability", + show_statis = TRUE, + show_censor = TRUE, + pval_method = "wald", + ties = "exact", + conf_level = 0.95, + legend_pos = "bottom", + position_coxph = c(0, 0.05), + position_surv_med = c(0.9, 0.9), + line_col = as.list(nestcolor::color_palette()), + ... +) + +kmg01_1_pre(adam_db, dataset, paramcd = "OS", ...) + +kmg01_1_post(tlg, ...) + +kmg01_1 +} +\arguments{ +\item{adam_db}{(\code{dm}) object containing the \code{ADaM} datasets} + +\item{dataset}{(\code{string}) the name of a table in the \code{adam_db} object.} + +\item{arm_var}{(\code{string}) variable used for column splitting} + +\item{x_name}{(\code{string}) the name of the x-axis.} + +\item{y_name}{(\code{string}) the name of the x-axis.} + +\item{show_statis}{(\code{flag}) should the summary statistic table be displayed.} + +\item{show_censor}{(\code{flag}) should the censor flag be displayed.} + +\item{pval_method}{(\code{string}) should the censor flag be displayed.} + +\item{ties}{(\code{string}) should the censor flag be displayed.} + +\item{conf_level}{(\code{number}) should the censor flag be displayed.} + +\item{legend_pos}{(\code{string}) the position of the legend.} + +\item{line_col}{(\code{list}) describing the colors to use for the lines or a named \code{list} associating values of \code{arm_var} +with color names.} + +\item{...}{not used.} + +\item{tlg}{(\code{TableTree}, \code{Listing} or \code{ggplot}) object typically produced by a \code{main} function.} +} +\value{ +a list of \code{ggplot} objects. +} +\description{ +\code{KMG01} Kaplan-Meier Plot 1. +} +\details{ +\itemize{ +\item No overall value. +} +} +\section{Functions}{ +\itemize{ +\item \code{kmg01_1_main()}: Main TLG Function + +\item \code{kmg01_1_pre()}: Preprocessing + +\item \code{kmg01_1_post()}: Postprocessing + +}} +\note{ +\itemize{ +\item \code{adam_db} object must contain the table specified by \code{dataset} with the columns specified by \code{arm_var}. +} +} +\examples{ +library(dm) +library(dplyr) + +col <- c( + "A: Drug X" = "black", + "B: Placebo" = "blue", + "C: Combination" = "gray" +) + +run(kmg01_1, syn_data, dataset = "adtte", line_col = col) +} +\keyword{datasets} diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R new file mode 100644 index 0000000000..91379c9257 --- /dev/null +++ b/tests/testthat/test-kmg01.R @@ -0,0 +1,26 @@ +test_that("kmg01_1 works as expected", { + pre_data <- expect_silent(kmg01_1_pre(syn_data, dataset = "adtte")) + raw_res <- expect_silent(kmg01_1_main(pre_data, dataset = "adtte")) + checkmate::assert_true(grid::is.grob(raw_res)) +}) + + + +test_that("kmg01_1 works as expected with custom color set", { + col <- list( + "A: Drug X" = "black", + "B: Placebo" = "blue", + "C: Combination" = "gray" + ) + + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = col)) + checkmate::assert_true(grid::is.grob(res)) + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = unname(col))) + checkmate::assert_true(grid::is.grob(res)) +}) + +test_that("kmg01_1 works if show_statis/show_censor is FALSE", { + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, show_censor = FALSE)) + checkmate::assert_true(grid::is.grob(res)) +}) + From eaea7cd1873b48c647f5c82c60538d1fc4773dcc Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 08:17:03 +0000 Subject: [PATCH 02/32] solve checks --- R/kmg01.R | 4 ++-- man/kmg01_1.Rd | 2 +- tests/testthat/_snaps/default_tlg.md | 19 +++++++++++++++++++ tests/testthat/test-kmg01.R | 1 - 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index aa8073b9e9..4fdb9241df 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -25,7 +25,7 @@ #' @export kmg01_1_main <- function(adam_db, dataset = "adtte", - arm_var = "ARMCD", + arm_var = "ARM", x_name = "Time (Days)", y_name = "Survival Probability", show_statis = TRUE, @@ -45,6 +45,7 @@ kmg01_1_main <- function(adam_db, checkmate::assert_flag(show_statis) checkmate::assert_flag(show_censor) + line_col <- unlist(line_col) checkmate::assert_character(line_col, null.ok = TRUE) variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) @@ -93,7 +94,6 @@ kmg01_1_main <- function(adam_db, position_surv_med = position_surv_med ) } - } #' @describeIn kmg01_1 Preprocessing diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index e766ddb3dd..ff5368c3be 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -14,7 +14,7 @@ An object of class \code{chevron_g} of length 1. kmg01_1_main( adam_db, dataset = "adtte", - arm_var = "ARMCD", + arm_var = "ARM", x_name = "Time (Days)", y_name = "Survival Probability", show_statis = TRUE, diff --git a/tests/testthat/_snaps/default_tlg.md b/tests/testthat/_snaps/default_tlg.md index a3dcdf4f69..6d1fc4e22e 100644 --- a/tests/testthat/_snaps/default_tlg.md +++ b/tests/testthat/_snaps/default_tlg.md @@ -371,6 +371,25 @@ Grade 3-4 43 (32.1%) 46 (34.3%) 43 (32.6%) 4 43 (32.1%) 46 (34.3%) 43 (32.6%) +# aet10_1 functions with default argument value return expected result with test data + + Code + res + Output + A: Drug X B: Placebo C: Combination + MedDRA Preferred Term (N=134) (N=134) (N=132) + ———————————————————————————————————————————————————————————————— + dcd D.2.1.5.3 47 (35.1%) 58 (43.3%) 57 (43.2%) + dcd A.1.1.1.1 50 (37.3%) 45 (33.6%) 63 (47.7%) + dcd B.2.2.3.1 48 (35.8%) 54 (40.3%) 51 (38.6%) + dcd A.1.1.1.2 48 (35.8%) 48 (35.8%) 50 (37.9%) + dcd B.2.1.2.1 49 (36.6%) 44 (32.8%) 52 (39.4%) + dcd D.1.1.1.1 50 (37.3%) 42 (31.3%) 51 (38.6%) + dcd D.1.1.4.2 48 (35.8%) 42 (31.3%) 50 (37.9%) + dcd B.1.1.1.1 47 (35.1%) 49 (36.6%) 43 (32.6%) + dcd C.2.1.2.1 35 (26.1%) 48 (35.8%) 55 (41.7%) + dcd C.1.1.1.3 43 (32.1%) 46 (34.3%) 43 (32.6%) + # cmt01a_1 functions with default argument value return expected result with test data Code diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index 91379c9257..ddb353dc32 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -23,4 +23,3 @@ test_that("kmg01_1 works if show_statis/show_censor is FALSE", { res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, show_censor = FALSE)) checkmate::assert_true(grid::is.grob(res)) }) - From d146c6ed3a1ee658ce82c68d5cb9783154c37a4d Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 08:22:48 +0000 Subject: [PATCH 03/32] Update wordlist --- inst/WORDLIST | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index 24c5211873..ffbb02cf5e 100755 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -2,22 +2,20 @@ ADEG ADaM AESI CTCAE -gg -gg_list Hoffmann +Kaplan NCI PARAMCD Postprocessing -postprocessing -preprocess Pre Repo -SSO +Rua TLG TLGs +de funder +postprocessing pre +preprocess repo reproducibility -de -Rua From beccf8511c1027698f4ce495a46d41efda53b803 Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 08:30:19 +0000 Subject: [PATCH 04/32] Update pkgdown --- _pkgdown.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yaml b/_pkgdown.yaml index 0c0e0797e6..f8363398a6 100755 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -70,6 +70,7 @@ reference: - egt05_qtcat_1 - ext01_1 - ext01_2 + - kmg01_1 - lbt01_1 - lbt04_1 - lbt05_1 From 00d88045f29d88fb9c91bcabe1538b22d598aeef Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 14:26:59 +0000 Subject: [PATCH 05/32] Add arguments --- R/kmg01.R | 5 ++++- man/kmg01_1.Rd | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/R/kmg01.R b/R/kmg01.R index 4fdb9241df..6d50c977d3 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -15,6 +15,8 @@ #' @param ties (`string`) should the censor flag be displayed. #' @param conf_level (`number`) should the censor flag be displayed. #' @param legend_pos (`string`) the position of the legend. +#' @param position_coxph +#' @param position_surv_med #' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var` #' with color names. #' @@ -54,7 +56,7 @@ kmg01_1_main <- function(adam_db, ggplot2::theme(legend.position = legend_pos) if (!is.null(names(line_col))) { - color_lvl <- sort(unique(df[[arm_var]])) + color_lvl <- sort(unique(anl[[arm_var]])) col <- line_col[as.character(color_lvl)] if (anyNA(col)) { @@ -99,6 +101,7 @@ kmg01_1_main <- function(adam_db, #' @describeIn kmg01_1 Preprocessing #' #' @inheritParams kmg01_1_main +#' @param paramcd (`string`) PARAMCD of the endpoint need to be analysis #' #' @export kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index ff5368c3be..aafbb85fef 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -63,6 +63,8 @@ with color names.} \item{...}{not used.} +\item{paramcd}{(\code{string}) PARAMCD of the endpoint need to be analysis} + \item{tlg}{(\code{TableTree}, \code{Listing} or \code{ggplot}) object typically produced by a \code{main} function.} } \value{ From a554eb4576b8a397de99c3a91581e03b6970f5a1 Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 15:03:27 +0000 Subject: [PATCH 06/32] Add new checks and update document --- R/kmg01.R | 7 ++++--- man/kmg01_1.Rd | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 6d50c977d3..4f32e3ebf9 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -13,10 +13,10 @@ #' @param show_censor (`flag`) should the censor flag be displayed. #' @param pval_method (`string`) should the censor flag be displayed. #' @param ties (`string`) should the censor flag be displayed. -#' @param conf_level (`number`) should the censor flag be displayed. +#' @param conf_level (`numeric`) should the censor flag be displayed. #' @param legend_pos (`string`) the position of the legend. -#' @param position_coxph -#' @param position_surv_med +#' @param position_coxph (`numeric`) x and y positions for plotting survival::coxph() model. +#' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating median survival time per group. #' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var` #' with color names. #' @@ -106,6 +106,7 @@ kmg01_1_main <- function(adam_db, #' @export kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { checkmate::assert_class(adam_db, "dm") + assert_colnames(adam_db[[dataset]], c("PARAMCD", "CNSR")) adam_db <- adam_db %>% dm_zoom_to(!!dataset) %>% diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index aafbb85fef..7197e3bcae 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -54,10 +54,14 @@ kmg01_1 \item{ties}{(\code{string}) should the censor flag be displayed.} -\item{conf_level}{(\code{number}) should the censor flag be displayed.} +\item{conf_level}{(\code{numeric}) should the censor flag be displayed.} \item{legend_pos}{(\code{string}) the position of the legend.} +\item{position_coxph}{(\code{numeric}) x and y positions for plotting survival::coxph() model.} + +\item{position_surv_med}{(\code{numeric}) x and y positions for plotting annotation table estimating median survival time per group.} + \item{line_col}{(\code{list}) describing the colors to use for the lines or a named \code{list} associating values of \code{arm_var} with color names.} From 68dd797fae9e04f707555c9864c85e216f851673 Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 15:21:18 +0000 Subject: [PATCH 07/32] Add line breaker --- R/kmg01.R | 3 ++- man/kmg01_1.Rd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 4f32e3ebf9..1276053464 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -16,7 +16,8 @@ #' @param conf_level (`numeric`) should the censor flag be displayed. #' @param legend_pos (`string`) the position of the legend. #' @param position_coxph (`numeric`) x and y positions for plotting survival::coxph() model. -#' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating median survival time per group. +#' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating +#' median survival time per group. #' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var` #' with color names. #' diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 7197e3bcae..9cb95d8032 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -60,7 +60,8 @@ kmg01_1 \item{position_coxph}{(\code{numeric}) x and y positions for plotting survival::coxph() model.} -\item{position_surv_med}{(\code{numeric}) x and y positions for plotting annotation table estimating median survival time per group.} +\item{position_surv_med}{(\code{numeric}) x and y positions for plotting annotation table estimating +median survival time per group.} \item{line_col}{(\code{list}) describing the colors to use for the lines or a named \code{list} associating values of \code{arm_var} with color names.} From 288dc87ac48ff631e47c34ae578b835b0d6e7b22 Mon Sep 17 00:00:00 2001 From: Chenkai Lv Date: Thu, 13 Apr 2023 15:27:43 +0000 Subject: [PATCH 08/32] Update wordlist --- inst/WORDLIST | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index ffbb02cf5e..d92ee080d4 100755 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -12,6 +12,7 @@ Repo Rua TLG TLGs +coxph de funder postprocessing From 62c5d038047c45ca330c44c8005c0c9d468bea31 Mon Sep 17 00:00:00 2001 From: Teninq Date: Wed, 19 Apr 2023 07:52:31 +0000 Subject: [PATCH 09/32] Update comments and documents --- NAMESPACE | 1 + R/kmg01.R | 58 +++++++++++++------------------------ man/kmg01_1.Rd | 5 +--- tests/testthat/test-kmg01.R | 20 ++++++++++--- 4 files changed, 38 insertions(+), 46 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 5f7f7f75e6..2fc6fa4690 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -152,6 +152,7 @@ export(grob_list) export(h_format_dec) export(kmg01_1) export(kmg01_1_main) +export(kmg01_1_post) export(kmg01_1_pre) export(lbt01_1) export(lbt01_1_lyt) diff --git a/R/kmg01.R b/R/kmg01.R index 1276053464..48327ec6ce 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -14,7 +14,6 @@ #' @param pval_method (`string`) should the censor flag be displayed. #' @param ties (`string`) should the censor flag be displayed. #' @param conf_level (`numeric`) should the censor flag be displayed. -#' @param legend_pos (`string`) the position of the legend. #' @param position_coxph (`numeric`) x and y positions for plotting survival::coxph() model. #' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating #' median survival time per group. @@ -36,15 +35,14 @@ kmg01_1_main <- function(adam_db, pval_method = "wald", ties = "exact", conf_level = 0.95, - legend_pos = "bottom", position_coxph = c(0, 0.05), position_surv_med = c(0.9, 0.9), line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] checkmate::assert_true(length(unique(anl$PARAMCD)) == 1) - checkmate::assert_character(x_name) - checkmate::assert_character(y_name) + checkmate::assert_string(x_name) + checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) checkmate::assert_flag(show_censor) @@ -53,8 +51,6 @@ kmg01_1_main <- function(adam_db, variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) - ggtheme <- ggplot2::theme_bw() + - ggplot2::theme(legend.position = legend_pos) if (!is.null(names(line_col))) { color_lvl <- sort(unique(anl[[arm_var]])) @@ -70,33 +66,18 @@ kmg01_1_main <- function(adam_db, col <- line_col } - gkm_plot <- if (!show_statis) { - g_km( - df = anl, - variables = variables, - censor_show = show_censor, - xlab = x_name, - ylab = y_name, - annot_surv_med = TRUE, - control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), - ggtheme = ggtheme, - position_coxph = position_coxph, - position_surv_med = position_surv_med - ) - } else { - g_km( - df = anl, - variables = variables, - censor_show = show_censor, - xlab = x_name, - ylab = y_name, - annot_coxph = TRUE, - control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), - ggtheme = ggtheme, - position_coxph = position_coxph, - position_surv_med = position_surv_med - ) - } + gkm_plot <- g_km( + df = anl, + variables = variables, + censor_show = show_censor, + xlab = x_name, + ylab = y_name, + annot_surv_med = !show_statis, + annot_coxph = show_statis, + control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), + position_coxph = position_coxph, + position_surv_med = position_surv_med + ) } #' @describeIn kmg01_1 Preprocessing @@ -106,20 +87,21 @@ kmg01_1_main <- function(adam_db, #' #' @export kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { - checkmate::assert_class(adam_db, "dm") + assert_all_tablenames(adam_db, c("adsl", "adtte")) assert_colnames(adam_db[[dataset]], c("PARAMCD", "CNSR")) - adam_db <- adam_db %>% - dm_zoom_to(!!dataset) %>% + adam_db$adtte <- adam_db$adtte %>% filter(.data$PARAMCD == paramcd) %>% - mutate(is_event = CNSR == 0) %>% - dm_update_zoomed() + mutate(is_event = CNSR == 0) + + adam_db } #' @describeIn kmg01_1 Postprocessing #' #' @inheritParams gen_args #' +#' @export kmg01_1_post <- function(tlg, ...) { tlg } diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 9cb95d8032..f5d6e67080 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -22,7 +22,6 @@ kmg01_1_main( pval_method = "wald", ties = "exact", conf_level = 0.95, - legend_pos = "bottom", position_coxph = c(0, 0.05), position_surv_med = c(0.9, 0.9), line_col = as.list(nestcolor::color_palette()), @@ -36,7 +35,7 @@ kmg01_1_post(tlg, ...) kmg01_1 } \arguments{ -\item{adam_db}{(\code{dm}) object containing the \code{ADaM} datasets} +\item{adam_db}{(\code{list} of \code{data.frames}) object containing the \code{ADaM} datasets} \item{dataset}{(\code{string}) the name of a table in the \code{adam_db} object.} @@ -56,8 +55,6 @@ kmg01_1 \item{conf_level}{(\code{numeric}) should the censor flag be displayed.} -\item{legend_pos}{(\code{string}) the position of the legend.} - \item{position_coxph}{(\code{numeric}) x and y positions for plotting survival::coxph() model.} \item{position_surv_med}{(\code{numeric}) x and y positions for plotting annotation table estimating diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index ddb353dc32..a9e5c73a63 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -4,8 +4,6 @@ test_that("kmg01_1 works as expected", { checkmate::assert_true(grid::is.grob(raw_res)) }) - - test_that("kmg01_1 works as expected with custom color set", { col <- list( "A: Drug X" = "black", @@ -19,7 +17,21 @@ test_that("kmg01_1 works as expected with custom color set", { checkmate::assert_true(grid::is.grob(res)) }) -test_that("kmg01_1 works if show_statis/show_censor is FALSE", { - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, show_censor = FALSE)) +test_that("kmg01_1 works if change pvalue, ties and conf level", { + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", + pval_method = "log-rank", + ties = "efron", + conf_level = 0.99)) + checkmate::assert_true(grid::is.grob(res)) +}) + +test_that("kmg01_1 works if change legend postion", { + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", legend_pos = "right")) + checkmate::assert_true(grid::is.grob(res)) +}) + +test_that("kmg01_1 works if change annotation position", { + res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, + position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7))) checkmate::assert_true(grid::is.grob(res)) }) From 49bd8fc83aebd468ef6d6d091b07bad54c448bcd Mon Sep 17 00:00:00 2001 From: LVC11 Date: Wed, 19 Apr 2023 07:58:49 +0000 Subject: [PATCH 10/32] Update style --- tests/testthat/test-kmg01.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index a9e5c73a63..8fbd33a89c 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -18,10 +18,12 @@ test_that("kmg01_1 works as expected with custom color set", { }) test_that("kmg01_1 works if change pvalue, ties and conf level", { - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", - pval_method = "log-rank", - ties = "efron", - conf_level = 0.99)) + res <- expect_silent(run(kmg01_1, syn_data, + dataset = "adtte", + pval_method = "log-rank", + ties = "efron", + conf_level = 0.99 + )) checkmate::assert_true(grid::is.grob(res)) }) @@ -31,7 +33,9 @@ test_that("kmg01_1 works if change legend postion", { }) test_that("kmg01_1 works if change annotation position", { - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", show_statis = FALSE, - position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7))) + res <- expect_silent(run(kmg01_1, syn_data, + dataset = "adtte", show_statis = FALSE, + position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7) + )) checkmate::assert_true(grid::is.grob(res)) }) From dc659bbf733c71c97caa2cccb788657efe6f8a0a Mon Sep 17 00:00:00 2001 From: LVC11 Date: Wed, 19 Apr 2023 08:18:10 +0000 Subject: [PATCH 11/32] Update unit test to remove legend position --- tests/testthat/test-kmg01.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index 8fbd33a89c..ac8402b067 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -27,10 +27,6 @@ test_that("kmg01_1 works if change pvalue, ties and conf level", { checkmate::assert_true(grid::is.grob(res)) }) -test_that("kmg01_1 works if change legend postion", { - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", legend_pos = "right")) - checkmate::assert_true(grid::is.grob(res)) -}) test_that("kmg01_1 works if change annotation position", { res <- expect_silent(run(kmg01_1, syn_data, From 02a02bcb6b490f1a701df2491dffa797ab42e82c Mon Sep 17 00:00:00 2001 From: LVC11 Date: Wed, 19 Apr 2023 11:57:08 +0000 Subject: [PATCH 12/32] Remove library dm --- R/kmg01.R | 1 - man/kmg01_1.Rd | 1 - 2 files changed, 2 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 48327ec6ce..80ce151057 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -115,7 +115,6 @@ kmg01_1_post <- function(tlg, ...) { #' @export #' #' @examples -#' library(dm) #' library(dplyr) #' #' col <- c( diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index f5d6e67080..25f46b0be3 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -95,7 +95,6 @@ a list of \code{ggplot} objects. } } \examples{ -library(dm) library(dplyr) col <- c( From 973cb48355f661f75baf588111602f85f3d37262 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Wed, 19 Apr 2023 14:38:23 +0000 Subject: [PATCH 13/32] Update line widths --- R/kmg01.R | 4 ++-- man/kmg01_1.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 80ce151057..6fc1fc9664 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -17,8 +17,8 @@ #' @param position_coxph (`numeric`) x and y positions for plotting survival::coxph() model. #' @param position_surv_med (`numeric`) x and y positions for plotting annotation table estimating #' median survival time per group. -#' @param line_col (`list`) describing the colors to use for the lines or a named `list` associating values of `arm_var` -#' with color names. +#' @param line_col (`list`) describing the colors to use for the lines or a named `list` +#' associating values of `arm_var` with color names. #' #' @note #' * `adam_db` object must contain the table specified by `dataset` with the columns specified by `arm_var`. diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 25f46b0be3..5984a0f19f 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -60,8 +60,8 @@ kmg01_1 \item{position_surv_med}{(\code{numeric}) x and y positions for plotting annotation table estimating median survival time per group.} -\item{line_col}{(\code{list}) describing the colors to use for the lines or a named \code{list} associating values of \code{arm_var} -with color names.} +\item{line_col}{(\code{list}) describing the colors to use for the lines or a named \code{list} +associating values of \code{arm_var} with color names.} \item{...}{not used.} From 2584a658a1c15bffcbdd8044ba1defc2cabb0442 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 02:33:49 +0000 Subject: [PATCH 14/32] add aval assertion --- R/kmg01.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/kmg01.R b/R/kmg01.R index 6fc1fc9664..7d71752dc8 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -49,6 +49,7 @@ kmg01_1_main <- function(adam_db, line_col <- unlist(line_col) checkmate::assert_character(line_col, null.ok = TRUE) + assert_colnames(adam_db[[dataset]], "AVAL") variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) @@ -92,7 +93,7 @@ kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { adam_db$adtte <- adam_db$adtte %>% filter(.data$PARAMCD == paramcd) %>% - mutate(is_event = CNSR == 0) + mutate(is_event = .data$CNSR == 0) adam_db } From 4f5d725ff0754a54d4aca5c42c2ec94ec4aea883 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 02:57:14 +0000 Subject: [PATCH 15/32] Update with latest dunlin --- R/kmg01.R | 10 +++++----- man/kmg01_1.Rd | 9 +++++---- tests/testthat/test-kmg01.R | 12 +++++++----- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 7d71752dc8..cf73d6593c 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -87,12 +87,11 @@ kmg01_1_main <- function(adam_db, #' @param paramcd (`string`) PARAMCD of the endpoint need to be analysis #' #' @export -kmg01_1_pre <- function(adam_db, dataset, paramcd = "OS", ...) { - assert_all_tablenames(adam_db, c("adsl", "adtte")) - assert_colnames(adam_db[[dataset]], c("PARAMCD", "CNSR")) +kmg01_1_pre <- function(adam_db, dataset = "adtte", ...) { + assert_all_tablenames(adam_db, c("adsl", dataset)) + assert_colnames(adam_db[[dataset]], "CNSR") adam_db$adtte <- adam_db$adtte %>% - filter(.data$PARAMCD == paramcd) %>% mutate(is_event = .data$CNSR == 0) adam_db @@ -124,7 +123,8 @@ kmg01_1_post <- function(tlg, ...) { #' "C: Combination" = "gray" #' ) #' -#' run(kmg01_1, syn_data, dataset = "adtte", line_col = col) +#' syn_data2 <- log_filter(syn_data, PARAMCD == "OS", "adtte") +#' run(kmg01_1, syn_data2, dataset = "adtte", line_col = col) kmg01_1 <- chevron_g( main = kmg01_1_main, preproces = kmg01_1_pre, diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 5984a0f19f..3a0621a912 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -28,7 +28,7 @@ kmg01_1_main( ... ) -kmg01_1_pre(adam_db, dataset, paramcd = "OS", ...) +kmg01_1_pre(adam_db, dataset = "adtte", ...) kmg01_1_post(tlg, ...) @@ -65,9 +65,9 @@ associating values of \code{arm_var} with color names.} \item{...}{not used.} -\item{paramcd}{(\code{string}) PARAMCD of the endpoint need to be analysis} - \item{tlg}{(\code{TableTree}, \code{Listing} or \code{ggplot}) object typically produced by a \code{main} function.} + +\item{paramcd}{(\code{string}) PARAMCD of the endpoint need to be analysis} } \value{ a list of \code{ggplot} objects. @@ -103,6 +103,7 @@ col <- c( "C: Combination" = "gray" ) -run(kmg01_1, syn_data, dataset = "adtte", line_col = col) +syn_data2 <- log_filter(syn_data, PARAMCD == "OS", "adtte") +run(kmg01_1, syn_data2, dataset = "adtte", line_col = col) } \keyword{datasets} diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index ac8402b067..2bda1a5013 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -1,5 +1,6 @@ test_that("kmg01_1 works as expected", { - pre_data <- expect_silent(kmg01_1_pre(syn_data, dataset = "adtte")) + filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") + pre_data <- expect_silent(kmg01_1_pre(filter_data, dataset = "adtte")) raw_res <- expect_silent(kmg01_1_main(pre_data, dataset = "adtte")) checkmate::assert_true(grid::is.grob(raw_res)) }) @@ -11,14 +12,14 @@ test_that("kmg01_1 works as expected with custom color set", { "C: Combination" = "gray" ) - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = col)) + res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = col)) checkmate::assert_true(grid::is.grob(res)) - res <- expect_silent(run(kmg01_1, syn_data, dataset = "adtte", line_col = unname(col))) + res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = unname(col))) checkmate::assert_true(grid::is.grob(res)) }) test_that("kmg01_1 works if change pvalue, ties and conf level", { - res <- expect_silent(run(kmg01_1, syn_data, + res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", pval_method = "log-rank", ties = "efron", @@ -29,9 +30,10 @@ test_that("kmg01_1 works if change pvalue, ties and conf level", { test_that("kmg01_1 works if change annotation position", { - res <- expect_silent(run(kmg01_1, syn_data, + res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", show_statis = FALSE, position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7) )) checkmate::assert_true(grid::is.grob(res)) }) + From a0f412911a0af9f47c55726c5bf5f3babf5b12e7 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 03:35:03 +0000 Subject: [PATCH 16/32] Update testthat --- R/kmg01.R | 1 + man/kmg01_1.Rd | 1 + tests/testthat/test-kmg01.R | 3 +++ 3 files changed, 5 insertions(+) diff --git a/R/kmg01.R b/R/kmg01.R index cf73d6593c..178e578c0b 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -116,6 +116,7 @@ kmg01_1_post <- function(tlg, ...) { #' #' @examples #' library(dplyr) +#' library(dunlin) #' #' col <- c( #' "A: Drug X" = "black", diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 3a0621a912..5f797be662 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -96,6 +96,7 @@ a list of \code{ggplot} objects. } \examples{ library(dplyr) +library(dunlin) col <- c( "A: Drug X" = "black", diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index 2bda1a5013..9f5bda32dd 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -12,6 +12,7 @@ test_that("kmg01_1 works as expected with custom color set", { "C: Combination" = "gray" ) + filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = col)) checkmate::assert_true(grid::is.grob(res)) res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = unname(col))) @@ -19,6 +20,7 @@ test_that("kmg01_1 works as expected with custom color set", { }) test_that("kmg01_1 works if change pvalue, ties and conf level", { + filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", pval_method = "log-rank", @@ -30,6 +32,7 @@ test_that("kmg01_1 works if change pvalue, ties and conf level", { test_that("kmg01_1 works if change annotation position", { + filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", show_statis = FALSE, position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7) From 6c384bc531021384cf0fe00318dd0453103c6014 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 04:44:25 +0000 Subject: [PATCH 17/32] Load dunlin --- tests/testthat/test-kmg01.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index 9f5bda32dd..06507cd979 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -1,5 +1,5 @@ test_that("kmg01_1 works as expected", { - filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") + filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte") pre_data <- expect_silent(kmg01_1_pre(filter_data, dataset = "adtte")) raw_res <- expect_silent(kmg01_1_main(pre_data, dataset = "adtte")) checkmate::assert_true(grid::is.grob(raw_res)) @@ -12,7 +12,7 @@ test_that("kmg01_1 works as expected with custom color set", { "C: Combination" = "gray" ) - filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") + filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = col)) checkmate::assert_true(grid::is.grob(res)) res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", line_col = unname(col))) @@ -20,7 +20,7 @@ test_that("kmg01_1 works as expected with custom color set", { }) test_that("kmg01_1 works if change pvalue, ties and conf level", { - filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") + filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", pval_method = "log-rank", @@ -32,7 +32,7 @@ test_that("kmg01_1 works if change pvalue, ties and conf level", { test_that("kmg01_1 works if change annotation position", { - filter_data <- log_filter(syn_data, PARAMCD == "OS", "adtte") + filter_data <- dunlin::log_filter(syn_data, PARAMCD == "OS", "adtte") res <- expect_silent(run(kmg01_1, filter_data, dataset = "adtte", show_statis = FALSE, position_coxph = c(0.4, 0.5), position_surv_med = c(1, 0.7) From 7265d98791865b8da2dd608299f11e999af7480f Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 04:50:20 +0000 Subject: [PATCH 18/32] Update style --- tests/testthat/test-kmg01.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-kmg01.R b/tests/testthat/test-kmg01.R index 06507cd979..d7cf44d46e 100644 --- a/tests/testthat/test-kmg01.R +++ b/tests/testthat/test-kmg01.R @@ -39,4 +39,3 @@ test_that("kmg01_1 works if change annotation position", { )) checkmate::assert_true(grid::is.grob(res)) }) - From 6c9959d310b6f7c926e0ad7d4eff58f8cd4dbe8e Mon Sep 17 00:00:00 2001 From: Liming Li Date: Thu, 20 Apr 2023 06:46:51 +0000 Subject: [PATCH 19/32] update gitignore --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f7e7e96156..9e15e1d9d2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,12 +3,10 @@ .RData .Ruserdata .DS_Store -InputVads.Rdata -t_ae_ctc_SE.out -t_ae_ctc_ATEZOREL_SENBX.out inst/doc docs temp *.bak .Renviron .Rprofile +.vscode From d862ad27bf9fa63c672d356d9c14b07374b52e33 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 07:07:33 +0000 Subject: [PATCH 20/32] Update paramcd assertion --- R/kmg01.R | 3 +-- man/kmg01_1.Rd | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/R/kmg01.R b/R/kmg01.R index 178e578c0b..5386126cd7 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -40,7 +40,7 @@ kmg01_1_main <- function(adam_db, line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] - checkmate::assert_true(length(unique(anl$PARAMCD)) == 1) + checkmate::assert_true(length(unique(anl$PARAMCD)) == 1, msg = "Only one parameter should be used in the analysis dataset") checkmate::assert_string(x_name) checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) @@ -84,7 +84,6 @@ kmg01_1_main <- function(adam_db, #' @describeIn kmg01_1 Preprocessing #' #' @inheritParams kmg01_1_main -#' @param paramcd (`string`) PARAMCD of the endpoint need to be analysis #' #' @export kmg01_1_pre <- function(adam_db, dataset = "adtte", ...) { diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index 5f797be662..e8da50c0d6 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -66,8 +66,6 @@ associating values of \code{arm_var} with color names.} \item{...}{not used.} \item{tlg}{(\code{TableTree}, \code{Listing} or \code{ggplot}) object typically produced by a \code{main} function.} - -\item{paramcd}{(\code{string}) PARAMCD of the endpoint need to be analysis} } \value{ a list of \code{ggplot} objects. From f0c05ba0ac5b5d1c083e791b686747a2704a6668 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 07:15:04 +0000 Subject: [PATCH 21/32] Update lint code --- R/kmg01.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/kmg01.R b/R/kmg01.R index 5386126cd7..c29c3b6db3 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -40,7 +40,8 @@ kmg01_1_main <- function(adam_db, line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] - checkmate::assert_true(length(unique(anl$PARAMCD)) == 1, msg = "Only one parameter should be used in the analysis dataset") + checkmate::assert_true(length(unique(anl$PARAMCD)) == 1, + msg = "Only one parameter should be used in the analysis dataset") checkmate::assert_string(x_name) checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) From a95703bede88e722760d118e3b00c7257a80c4dc Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 07:22:47 +0000 Subject: [PATCH 22/32] Update style --- R/kmg01.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/kmg01.R b/R/kmg01.R index c29c3b6db3..0c8afcf4c8 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -41,7 +41,8 @@ kmg01_1_main <- function(adam_db, ...) { anl <- adam_db[[dataset]] checkmate::assert_true(length(unique(anl$PARAMCD)) == 1, - msg = "Only one parameter should be used in the analysis dataset") + msg = "Only one parameter should be used in the analysis dataset" + ) checkmate::assert_string(x_name) checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) From 273e7ecef7ada0c8fac13e23dace94b5fa9dde00 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 08:27:32 +0000 Subject: [PATCH 23/32] Add assertion to check only one paramcd exists --- NAMESPACE | 1 + R/kmg01.R | 4 +--- R/utils.R | 9 +++++++++ man/assert_only_one_paramcd.Rd | 11 +++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 man/assert_only_one_paramcd.Rd diff --git a/NAMESPACE b/NAMESPACE index 2fc6fa4690..4cf4c66b9d 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ export(aet10_1_pre) export(args_ls) export(assert_all_tablenames) export(assert_colnames) +export(assert_only_one_paramcd) export(chevron_g) export(chevron_l) export(chevron_t) diff --git a/R/kmg01.R b/R/kmg01.R index 0c8afcf4c8..39861e7dc9 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -40,9 +40,7 @@ kmg01_1_main <- function(adam_db, line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] - checkmate::assert_true(length(unique(anl$PARAMCD)) == 1, - msg = "Only one parameter should be used in the analysis dataset" - ) + assert_only_one_paramcd(unique(anl$PARAMCD)) checkmate::assert_string(x_name) checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) diff --git a/R/utils.R b/R/utils.R index b2b05dae18..e96691d382 100755 --- a/R/utils.R +++ b/R/utils.R @@ -266,3 +266,12 @@ gg_list <- function(...) { class = c("gg_list", "list") ) } + +#' Check to have only one PARAMCD in the analysis dataset +#' @param param_val +#' @export +assert_only_one_paramcd <- function(param_val) { + if (length(param_val) > 1) { + stop(paste0("More than one parameters:", paste(param_val, collapse = ", "), ", Only one suppose to have.")) + } +} diff --git a/man/assert_only_one_paramcd.Rd b/man/assert_only_one_paramcd.Rd new file mode 100644 index 0000000000..a535018d25 --- /dev/null +++ b/man/assert_only_one_paramcd.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{assert_only_one_paramcd} +\alias{assert_only_one_paramcd} +\title{Check to have only one PARAMCD in the analysis dataset} +\usage{ +assert_only_one_paramcd(param_val) +} +\description{ +Check to have only one PARAMCD in the analysis dataset +} From 1ec7a571e55d2d3f91f7d5f6b7f95fa3eb084723 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 08:35:38 +0000 Subject: [PATCH 24/32] Add missing topic --- _pkgdown.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yaml b/_pkgdown.yaml index e1fbf7f1a9..a6ea263d11 100755 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -109,6 +109,7 @@ reference: - h_format_dec - gg_list - grob_list + - assert_only_one_paramcd - title: Non-exported Documented Functions for Packagage Developers contents: From 3d5cdf148c4c51f1ba01053a4172c4a37943f1c1 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 08:47:32 +0000 Subject: [PATCH 25/32] Add documentation to argument 'param_val' --- R/utils.R | 2 +- man/assert_only_one_paramcd.Rd | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index e96691d382..f81c926bdc 100755 --- a/R/utils.R +++ b/R/utils.R @@ -268,7 +268,7 @@ gg_list <- function(...) { } #' Check to have only one PARAMCD in the analysis dataset -#' @param param_val +#' @param param_val unique value of PARAMCD #' @export assert_only_one_paramcd <- function(param_val) { if (length(param_val) > 1) { diff --git a/man/assert_only_one_paramcd.Rd b/man/assert_only_one_paramcd.Rd index a535018d25..3956f2fb9b 100644 --- a/man/assert_only_one_paramcd.Rd +++ b/man/assert_only_one_paramcd.Rd @@ -6,6 +6,9 @@ \usage{ assert_only_one_paramcd(param_val) } +\arguments{ +\item{param_val}{unique value of PARAMCD} +} \description{ Check to have only one PARAMCD in the analysis dataset } From 547ce121f034ad62c015fb46c48d34785177e303 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 09:05:26 +0000 Subject: [PATCH 26/32] Update style --- R/utils.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index f81c926bdc..ce81d667dc 100755 --- a/R/utils.R +++ b/R/utils.R @@ -272,6 +272,10 @@ gg_list <- function(...) { #' @export assert_only_one_paramcd <- function(param_val) { if (length(param_val) > 1) { - stop(paste0("More than one parameters:", paste(param_val, collapse = ", "), ", Only one suppose to have.")) + stop(paste0( + "More than one parameters:", + paste(param_val, collapse = ", "), + ", Only one suppose to have." + )) } } From a6111e6e0489136d827017ca633ba39535c96436 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Thu, 20 Apr 2023 14:06:09 +0000 Subject: [PATCH 27/32] Update style and document --- R/ael01_nollt.R | 4 +++- R/kmg01.R | 2 +- man/ael01_nollt_1.Rd | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/R/ael01_nollt.R b/R/ael01_nollt.R index 8232d2ab25..eae52cf646 100644 --- a/R/ael01_nollt.R +++ b/R/ael01_nollt.R @@ -99,7 +99,9 @@ ael01_nollt_1_post <- function(tlg, ...) { #' @export #' #' @examples -#' run(ael01_nollt_1, syn_data, new_lbls = list(AETERM = "Investigator-Specified\n Adverse Event Term")) +#' run(ael01_nollt_1, syn_data, new_lbls = list( +#' AETERM = "Investigator-Specified\n Adverse Event Term" +#' )) ael01_nollt_1 <- chevron_l( main = ael01_nollt_1_main, preprocess = ael01_nollt_1_pre, diff --git a/R/kmg01.R b/R/kmg01.R index 39861e7dc9..8b703a91fe 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -75,7 +75,7 @@ kmg01_1_main <- function(adam_db, ylab = y_name, annot_surv_med = !show_statis, annot_coxph = show_statis, - control_coxph = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), + control_coxph_pw = control_coxph(pval_method = pval_method, ties = ties, conf_level = conf_level), position_coxph = position_coxph, position_surv_med = position_surv_med ) diff --git a/man/ael01_nollt_1.Rd b/man/ael01_nollt_1.Rd index 4f9c4b84bb..a319fe9d92 100644 --- a/man/ael01_nollt_1.Rd +++ b/man/ael01_nollt_1.Rd @@ -85,6 +85,8 @@ strings to the new labels to apply to the named variables. Set to \code{NULL} to } } \examples{ -run(ael01_nollt_1, syn_data, new_lbls = list(AETERM = "Investigator-Specified\n Adverse Event Term")) +run(ael01_nollt_1, syn_data, new_lbls = list( + AETERM = "Investigator-Specified\n Adverse Event Term" +)) } \keyword{datasets} From b9a2e5d8b434a194d3878823d6be097cf50ce573 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Fri, 21 Apr 2023 07:13:56 +0000 Subject: [PATCH 28/32] Update comments --- R/assertions.R | 16 ++++++++++++++++ R/kmg01.R | 14 +++++++++----- R/utils.R | 13 +------------ man/assert_only_one_paramcd.Rd | 4 ++-- man/kmg01_1.Rd | 5 ++++- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/R/assertions.R b/R/assertions.R index d203a2299d..e3aa806180 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -167,3 +167,19 @@ assert_subset_suggest <- function(x, choices) { stop(msg, call. = FALSE) } + + +#' Check to have only one PARAMCD in the analysis dataset +#' @param param_val (`character`) value of PARAMCD +#' @export +assert_only_one_paramcd <- function(param_val) { + unique_param_val <- unique(param_val) + if (length(unique_param_val) > 1) { + stop(paste0( + "More than one parameters:", + toString(unique_param_val), + ", only one suppose to have." + )) + } +} + diff --git a/R/kmg01.R b/R/kmg01.R index 8b703a91fe..be26f62d79 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -40,7 +40,8 @@ kmg01_1_main <- function(adam_db, line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] - assert_only_one_paramcd(unique(anl$PARAMCD)) + assert_colnames(anl, "PARAMCD") + assert_only_one_paramcd(anl$PARAMCD) checkmate::assert_string(x_name) checkmate::assert_string(y_name) checkmate::assert_flag(show_statis) @@ -67,7 +68,7 @@ kmg01_1_main <- function(adam_db, col <- line_col } - gkm_plot <- g_km( + g_km( df = anl, variables = variables, censor_show = show_censor, @@ -90,7 +91,7 @@ kmg01_1_pre <- function(adam_db, dataset = "adtte", ...) { assert_all_tablenames(adam_db, c("adsl", dataset)) assert_colnames(adam_db[[dataset]], "CNSR") - adam_db$adtte <- adam_db$adtte %>% + adam_db[[dataset]] <- adam_db[[dataset]] %>% mutate(is_event = .data$CNSR == 0) adam_db @@ -117,7 +118,7 @@ kmg01_1_post <- function(tlg, ...) { #' library(dplyr) #' library(dunlin) #' -#' col <- c( +#' col <- list( #' "A: Drug X" = "black", #' "B: Placebo" = "blue", #' "C: Combination" = "gray" @@ -125,9 +126,12 @@ kmg01_1_post <- function(tlg, ...) { #' #' syn_data2 <- log_filter(syn_data, PARAMCD == "OS", "adtte") #' run(kmg01_1, syn_data2, dataset = "adtte", line_col = col) +#' +#' syn_data3 <- log_filter(syn_data, PARAMCD == "AEREPTTE", "adaette") +#' run(kmg01_1, syn_data3, dataset = "adaette") kmg01_1 <- chevron_g( main = kmg01_1_main, preproces = kmg01_1_pre, postprocess = kmg01_1_post, - adam_datasets = c("adsl", "adtte") + adam_datasets = c("adsl") ) diff --git a/R/utils.R b/R/utils.R index ce81d667dc..f966caf468 100755 --- a/R/utils.R +++ b/R/utils.R @@ -267,15 +267,4 @@ gg_list <- function(...) { ) } -#' Check to have only one PARAMCD in the analysis dataset -#' @param param_val unique value of PARAMCD -#' @export -assert_only_one_paramcd <- function(param_val) { - if (length(param_val) > 1) { - stop(paste0( - "More than one parameters:", - paste(param_val, collapse = ", "), - ", Only one suppose to have." - )) - } -} + diff --git a/man/assert_only_one_paramcd.Rd b/man/assert_only_one_paramcd.Rd index 3956f2fb9b..3a22a19ed1 100644 --- a/man/assert_only_one_paramcd.Rd +++ b/man/assert_only_one_paramcd.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/assertions.R \name{assert_only_one_paramcd} \alias{assert_only_one_paramcd} \title{Check to have only one PARAMCD in the analysis dataset} @@ -7,7 +7,7 @@ assert_only_one_paramcd(param_val) } \arguments{ -\item{param_val}{unique value of PARAMCD} +\item{param_val}{(\code{character}) value of PARAMCD} } \description{ Check to have only one PARAMCD in the analysis dataset diff --git a/man/kmg01_1.Rd b/man/kmg01_1.Rd index e8da50c0d6..2f2acfcbc1 100644 --- a/man/kmg01_1.Rd +++ b/man/kmg01_1.Rd @@ -96,7 +96,7 @@ a list of \code{ggplot} objects. library(dplyr) library(dunlin) -col <- c( +col <- list( "A: Drug X" = "black", "B: Placebo" = "blue", "C: Combination" = "gray" @@ -104,5 +104,8 @@ col <- c( syn_data2 <- log_filter(syn_data, PARAMCD == "OS", "adtte") run(kmg01_1, syn_data2, dataset = "adtte", line_col = col) + +syn_data3 <- log_filter(syn_data, PARAMCD == "AEREPTTE", "adaette") +run(kmg01_1, syn_data3, dataset = "adaette") } \keyword{datasets} From 3883ebd7e5fdfb1cda6593f8311e5566ecedfb08 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Fri, 21 Apr 2023 07:20:51 +0000 Subject: [PATCH 29/32] Update style --- R/utils.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index f966caf468..b2b05dae18 100755 --- a/R/utils.R +++ b/R/utils.R @@ -266,5 +266,3 @@ gg_list <- function(...) { class = c("gg_list", "list") ) } - - From efded8aad2b0cf3d61721e837972273ac4e6c0e1 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Fri, 21 Apr 2023 07:27:17 +0000 Subject: [PATCH 30/32] Update style --- R/assertions.R | 1 - R/kmg01.R | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/R/assertions.R b/R/assertions.R index e3aa806180..d85cafe6cd 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -182,4 +182,3 @@ assert_only_one_paramcd <- function(param_val) { )) } } - diff --git a/R/kmg01.R b/R/kmg01.R index be26f62d79..c194b2d86d 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -50,7 +50,7 @@ kmg01_1_main <- function(adam_db, line_col <- unlist(line_col) checkmate::assert_character(line_col, null.ok = TRUE) - assert_colnames(adam_db[[dataset]], "AVAL") + assert_colnames(anl, "AVAL") variables <- list(tte = "AVAL", is_event = "is_event", arm = arm_var) From 756a8febaebd0a861513e8e4c4ccf8ab736202b7 Mon Sep 17 00:00:00 2001 From: LVC11 Date: Mon, 24 Apr 2023 02:34:46 +0000 Subject: [PATCH 31/32] Add check var_arm and is_event --- R/kmg01.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/kmg01.R b/R/kmg01.R index c194b2d86d..df9107be34 100644 --- a/R/kmg01.R +++ b/R/kmg01.R @@ -40,7 +40,7 @@ kmg01_1_main <- function(adam_db, line_col = as.list(nestcolor::color_palette()), ...) { anl <- adam_db[[dataset]] - assert_colnames(anl, "PARAMCD") + assert_colnames(anl, c("PARAMCD", "is_event", arm_var)) assert_only_one_paramcd(anl$PARAMCD) checkmate::assert_string(x_name) checkmate::assert_string(y_name) From d85e3dee15d46e0672b350e1ffe13a9ad145334b Mon Sep 17 00:00:00 2001 From: LVC11 Date: Mon, 24 Apr 2023 02:49:24 +0000 Subject: [PATCH 32/32] Remove type hint --- R/assertions.R | 2 +- man/assert_only_one_paramcd.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/assertions.R b/R/assertions.R index d85cafe6cd..aa0efefac0 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -170,7 +170,7 @@ assert_subset_suggest <- function(x, choices) { #' Check to have only one PARAMCD in the analysis dataset -#' @param param_val (`character`) value of PARAMCD +#' @param param_val value of PARAMCD #' @export assert_only_one_paramcd <- function(param_val) { unique_param_val <- unique(param_val) diff --git a/man/assert_only_one_paramcd.Rd b/man/assert_only_one_paramcd.Rd index 3a22a19ed1..474266247b 100644 --- a/man/assert_only_one_paramcd.Rd +++ b/man/assert_only_one_paramcd.Rd @@ -7,7 +7,7 @@ assert_only_one_paramcd(param_val) } \arguments{ -\item{param_val}{(\code{character}) value of PARAMCD} +\item{param_val}{value of PARAMCD} } \description{ Check to have only one PARAMCD in the analysis dataset