From 50e873d4d16e98652c0ee2515f56955650fbfb9c Mon Sep 17 00:00:00 2001 From: Jerry Johnson Date: Wed, 1 Nov 2023 20:50:49 +0000 Subject: [PATCH 1/8] feat: #2185 first implementation of `keep_source_vars` --- R/derive_param_tte.R | 13 +++++++++++-- man/derive_param_tte.Rd | 10 +++++++++- tests/testthat/test-derive_param_tte.R | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/R/derive_param_tte.R b/R/derive_param_tte.R index db870381d1..c50a5451c5 100644 --- a/R/derive_param_tte.R +++ b/R/derive_param_tte.R @@ -58,6 +58,14 @@ #' #' A list of symbols created using `exprs()` is expected. #' +#' @param keep_source_vars Variables to be kept in the new records +#' +#' A named list or tidyselect expressions created by `exprs()` defining the +#' variables to be kept for the new records. The variables specified for +#' `by_vars` and `set_values_to` need not be specified here as they are kept +#' automatically. +#' +#' #' @details The following steps are performed to create the observations of the #' new parameter: #' @@ -320,7 +328,8 @@ derive_param_tte <- function(dataset = NULL, censor_conditions, create_datetime = FALSE, set_values_to, - subject_keys = get_admiral_option("subject_keys")) { + subject_keys = get_admiral_option("subject_keys"), + keep_source_vars = exprs(everything())) { # checking and quoting # assert_data_frame(dataset, optional = TRUE) assert_vars(by_vars, optional = TRUE) @@ -445,7 +454,7 @@ derive_param_tte <- function(dataset = NULL, } # -vars2chr(by_vars) does not work for 3.5 # - new_param <- select(new_param, !!!negate_vars(by_vars)) + new_param <- select(new_param, !!!negate_vars(by_vars), !!!keep_source_vars) } # add new parameter to input dataset # diff --git a/man/derive_param_tte.Rd b/man/derive_param_tte.Rd index dc17c2b7f7..327afd46fe 100644 --- a/man/derive_param_tte.Rd +++ b/man/derive_param_tte.Rd @@ -14,7 +14,8 @@ derive_param_tte( censor_conditions, create_datetime = FALSE, set_values_to, - subject_keys = get_admiral_option("subject_keys") + subject_keys = get_admiral_option("subject_keys"), + keep_source_vars = exprs(everything()) ) } \arguments{ @@ -73,6 +74,13 @@ expressions, or \code{NA}.} \item{subject_keys}{Variables to uniquely identify a subject A list of symbols created using \code{exprs()} is expected.} + +\item{keep_source_vars}{Variables to be kept in the new records + +A named list or tidyselect expressions created by \code{exprs()} defining the +variables to be kept for the new records. The variables specified for +\code{by_vars} and \code{set_values_to} need not be specified here as they are kept +automatically.} } \value{ The input dataset with the new parameter added diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index f765a6f43b..39244bd940 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -400,7 +400,8 @@ test_that("derive_param_tte Test 5: by_vars parameter works correctly", { PARAM = paste("Time to First", AEDECOD, "Adverse Event"), PARCAT1 = "TTAE", PARCAT2 = AEDECOD - ) + ), + keep_source_vars = exprs(USUBJID) ), expected_output, keys = c("USUBJID", "PARAMCD") From 537936fc6ff4067bf49a569ba9e1629306fb8950 Mon Sep 17 00:00:00 2001 From: Jerry Johnson Date: Thu, 2 Nov 2023 16:19:22 +0000 Subject: [PATCH 2/8] feat: #2185 add news blurb --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 46306889d1..f18fa931a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,8 @@ were enhanced such that more than one summary variable can be derived, e.g., allow more control of the selection of records. It creates a temporary variable for the event number, which can be used in `order`. (#2140) +- The `keep_source_vars` argument was added to `derive_param_tte()` (#2185) + ## Breaking Changes - In `derive_summary_records()` and `get_summary_records()` the arguments From f094d4da220388fffdaf2f5c8a1d10223d55dc56 Mon Sep 17 00:00:00 2001 From: Jerry Johnson Date: Thu, 2 Nov 2023 16:23:14 +0000 Subject: [PATCH 3/8] test something --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index f18fa931a0..f390489ecc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,7 +17,7 @@ were enhanced such that more than one summary variable can be derived, e.g., allow more control of the selection of records. It creates a temporary variable for the event number, which can be used in `order`. (#2140) -- The `keep_source_vars` argument was added to `derive_param_tte()` (#2185) +- The `keep_source_vars` argument was added to `derive_param_tte()` for consistency (#2185) ## Breaking Changes From 4512455d1e9655a3d492045cf715485a6515b78f Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 8 Nov 2023 18:43:07 +0000 Subject: [PATCH 4/8] address keep_source_vars edits/feedback --- R/derive_param_tte.R | 4 ++-- tests/testthat/test-derive_param_tte.R | 9 +++++---- vignettes/higher_order.Rmd | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/R/derive_param_tte.R b/R/derive_param_tte.R index c50a5451c5..bce068193f 100644 --- a/R/derive_param_tte.R +++ b/R/derive_param_tte.R @@ -431,7 +431,7 @@ derive_param_tte <- function(dataset = NULL, } adsl <- dataset_adsl %>% - select(!!!adsl_vars) + select(!!!adsl_vars, !!!keep_source_vars) # create observations for new parameter # new_param <- filter_extreme( @@ -454,7 +454,7 @@ derive_param_tte <- function(dataset = NULL, } # -vars2chr(by_vars) does not work for 3.5 # - new_param <- select(new_param, !!!negate_vars(by_vars), !!!keep_source_vars) + new_param <- select(new_param, !!!negate_vars(by_vars)) } # add new parameter to input dataset # diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index 39244bd940..af98eef8c9 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -40,7 +40,7 @@ test_that("derive_param_tte Test 1: new observations with analysis date are deri PARAMCD = "OS", PARAM = "Overall Survival" ) %>% - left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF), by = "USUBJID") + left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF, DTHFL, DTHDT, LSTALVDT), by = "USUBJID") actual_output <- derive_param_tte( dataset_adsl = adsl, @@ -146,7 +146,7 @@ test_that("derive_param_tte Test 2: new parameter with analysis datetime is deri PARAM = "Progression Free Survival" ) %>% left_join( - select(adsl, USUBJID, STARTDTM = TRTSDTM, STARTDTF = TRTSDTF, STARTTMF = TRTSTMF), + select(adsl, USUBJID, STARTDTM = TRTSDTM, STARTDTF = TRTSDTF, STARTTMF = TRTSTMF, DTHFL, DTHDT), by = "USUBJID" ) @@ -251,7 +251,7 @@ test_that("derive_param_tte Test 3: no new observations for subjects not in ADSL PARAM = "Duration of Response" ) %>% left_join( - select(adsl, USUBJID, STARTDT = RSPDT), + select(adsl, USUBJID, STARTDT = RSPDT, DTHFL, DTHDT), by = "USUBJID" ) @@ -797,7 +797,8 @@ test_that("derive_param_tte Test 11: ensuring ADT is not NA because of missing s STUDYID = "AB42", PARAMCD = "ANYAETTE", PARAM = "Time to any first adverse event" - ) + ) %>% + left_join(select(adsl, USUBJID, LSTALVDT), by = "USUBJID") expect_dfs_equal( actual_output, diff --git a/vignettes/higher_order.Rmd b/vignettes/higher_order.Rmd index db73719473..5f80eada99 100644 --- a/vignettes/higher_order.Rmd +++ b/vignettes/higher_order.Rmd @@ -168,15 +168,16 @@ adaette <- call_derivation( ), dataset_adsl = adsl, source_datasets = list(adsl = adsl, adae = adae), - censor_conditions = list(lastalive_censor) + censor_conditions = list(lastalive_censor), + keep_source_vars = exprs(TRT01A, EOSSTT) ) ``` ```{r, eval=TRUE, echo=FALSE} adaette %>% - select(USUBJID, PARAMCD, STARTDT, ADT, CNSR, EVNTDESC, SRCDOM, SRCVAR) %>% + select(USUBJID, TRT01A, EOSSTT, PARAMCD, STARTDT, ADT, CNSR, EVNTDESC, SRCDOM, SRCVAR) %>% arrange(USUBJID, PARAMCD) %>% - dataset_vignette(display_vars = exprs(USUBJID, PARAMCD, STARTDT, ADT, CNSR, EVNTDESC, SRCDOM, SRCVAR)) + dataset_vignette(display_vars = exprs(USUBJID, TRT01A, EOSSTT, PARAMCD, STARTDT, ADT, CNSR, EVNTDESC, SRCDOM, SRCVAR)) ``` Developing your ADaM scripts this way using `call_derivation()` could give the From 6f386c130af6fd4d723280d3ed61bdf747ff7b49 Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 8 Nov 2023 18:55:24 +0000 Subject: [PATCH 5/8] fix vignette as well --- vignettes/bds_tte.Rmd | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/vignettes/bds_tte.Rmd b/vignettes/bds_tte.Rmd index 5456fa0b2c..5b0ff7c7a4 100644 --- a/vignettes/bds_tte.Rmd +++ b/vignettes/bds_tte.Rmd @@ -142,7 +142,8 @@ adtte <- derive_param_tte( event_conditions = list(ae_ser_event), censor_conditions = list(lastalive_censor), source_datasets = list(adsl = adsl, adae = adae), - set_values_to = exprs(PARAMCD = "TTAESER", PARAM = "Time to First Serious AE") + set_values_to = exprs(PARAMCD = "TTAESER", PARAM = "Time to First Serious AE"), + keep_source_vars = exprs("USUBJID") ) ``` ```{r, echo=FALSE} @@ -184,7 +185,8 @@ adtte <- derive_param_tte( start_date = TRTSDT, event_conditions = list(death), censor_conditions = list(lstalv), - set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival") + set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival"), + keep_source_vars = exprs("USUBJID") ) ``` ```{r, echo=FALSE} @@ -232,7 +234,8 @@ adtte <- derive_param_tte( source_datasets = list(adsl = adsl), event_conditions = list(death), censor_conditions = list(lstalv), - set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival") + set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival"), + keep_source_vars = exprs("USUBJID") ) ``` @@ -497,7 +500,8 @@ adaette <- call_derivation( adsl = adsl, ae = filter(adae, TRTEMFL == "Y") ), - censor_conditions = list(observation_end) + censor_conditions = list(observation_end), + keep_source_vars = exprs("USUBJID") ) ``` @@ -594,7 +598,8 @@ adtte <- derive_param_tte( PARAM = paste("Time to First", AEDECOD, "Adverse Event"), PARCAT1 = "TTAE", PARCAT2 = AEDECOD - ) + ), + keep_source_vars = exprs(USUBJID, AEDECOD) ) ``` From 663fc2e0fe14580d5a0160a8c829e255ad2090e3 Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 8 Nov 2023 18:56:48 +0000 Subject: [PATCH 6/8] get past lintr --- tests/testthat/test-derive_param_tte.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index af98eef8c9..a1f1697bae 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -40,7 +40,7 @@ test_that("derive_param_tte Test 1: new observations with analysis date are deri PARAMCD = "OS", PARAM = "Overall Survival" ) %>% - left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF, DTHFL, DTHDT, LSTALVDT), by = "USUBJID") + left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF, DTHFL, DTHDT, LSTALVDT), by = "USUBJID") #nolint actual_output <- derive_param_tte( dataset_adsl = adsl, @@ -146,7 +146,7 @@ test_that("derive_param_tte Test 2: new parameter with analysis datetime is deri PARAM = "Progression Free Survival" ) %>% left_join( - select(adsl, USUBJID, STARTDTM = TRTSDTM, STARTDTF = TRTSDTF, STARTTMF = TRTSTMF, DTHFL, DTHDT), + select(adsl, USUBJID, STARTDTM = TRTSDTM, STARTDTF = TRTSDTF, STARTTMF = TRTSTMF, DTHFL, DTHDT), # nolint by = "USUBJID" ) From 71fb4356bffb14a6663ffea461a31d395f79bedd Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 8 Nov 2023 19:04:56 +0000 Subject: [PATCH 7/8] chore: #2185 clean up errors --- vignettes/bds_tte.Rmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vignettes/bds_tte.Rmd b/vignettes/bds_tte.Rmd index 5b0ff7c7a4..5d2e0f818a 100644 --- a/vignettes/bds_tte.Rmd +++ b/vignettes/bds_tte.Rmd @@ -402,7 +402,8 @@ adtte <- derive_param_tte( start_date = TRTSDT, event_conditions = list(pd, death), censor_conditions = list(lastvisit, start), - set_values_to = exprs(PARAMCD = "PFS", PARAM = "Progression Free Survival") + set_values_to = exprs(PARAMCD = "PFS", PARAM = "Progression Free Survival"), + keep_source_vars = exprs(USUBJID) ) ``` @@ -599,7 +600,7 @@ adtte <- derive_param_tte( PARCAT1 = "TTAE", PARCAT2 = AEDECOD ), - keep_source_vars = exprs(USUBJID, AEDECOD) + keep_source_vars = exprs(USUBJID) ) ``` From fe35445b469374aa3f9233a7bb8e45845fefbc9c Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 8 Nov 2023 19:13:01 +0000 Subject: [PATCH 8/8] get past styler --- tests/testthat/test-derive_param_tte.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index a1f1697bae..2284bd6bfe 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -40,7 +40,7 @@ test_that("derive_param_tte Test 1: new observations with analysis date are deri PARAMCD = "OS", PARAM = "Overall Survival" ) %>% - left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF, DTHFL, DTHDT, LSTALVDT), by = "USUBJID") #nolint + left_join(select(adsl, USUBJID, STARTDT = TRTSDT, STARTDTF = TRTSDTF, DTHFL, DTHDT, LSTALVDT), by = "USUBJID") # nolint actual_output <- derive_param_tte( dataset_adsl = adsl,