From a07fe274554ae79c83f217086397434db00f25ff Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Thu, 10 Oct 2024 14:54:47 +0000 Subject: [PATCH 1/2] #2519 fix_param_tte: add test --- NEWS.md | 4 ++ tests/testthat/_snaps/derive_param_tte.md | 14 +++++- tests/testthat/test-derive_param_tte.R | 53 +++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 91fb0405c8..4ef1477c95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,10 @@ ## Updates of Existing Functions +- `derive_param_tte()` now provides a useful error message if in +`event_conditions` or `censor_conditions` a dataset is referenced which is not +specified in `source_datasets`. (#2519) + ## Breaking Changes - The following function arguments are entering the next phase of the deprecation process: (#2487) diff --git a/tests/testthat/_snaps/derive_param_tte.md b/tests/testthat/_snaps/derive_param_tte.md index 345583b324..f1438eca6c 100644 --- a/tests/testthat/_snaps/derive_param_tte.md +++ b/tests/testthat/_snaps/derive_param_tte.md @@ -49,7 +49,19 @@ See error message below: i In argument: `PARAM = past("Time to First", AEDECOD, "Adverse Event")`. Caused by error in `past()`: ! could not find function "past" -# list_tte_source_objects Test 13: error is issued if package does not exist +# derive_param_tte Test 13: error if dataset_name not in source_datsets + + Code + derive_param_tte(dataset_adsl = adsl, start_date = TRTSDT, event_conditions = list( + death), censor_conditions = list(lstalv), source_datasets = list(adsl = adsl), + set_values_to = exprs(PARAMCD = "OS", PARAM = "Overall Survival")) + Condition + Error in `derive_param_tte()`: + ! The dataset names must be included in the list specified for the `source_datasets` argument. + i Following names were provided by `source_datasets`: "adsl" + i But, `censor_conditions[[1]]$dataset_name = adls` + +# list_tte_source_objects Test 14: error is issued if package does not exist Code list_tte_source_objects(package = "tte") diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index 0feeb4b236..ceb996dba5 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -885,18 +885,63 @@ test_that("derive_param_tte Test 12: test dataset and dynamic byvars populated", ) }) +## Test 13: error if dataset_name not in source_datsets ---- +test_that("derive_param_tte Test 13: error if dataset_name not in source_datsets", { + adsl <- tibble::tribble( + ~USUBJID, ~DTHFL, ~DTHDT, ~LSTALVDT, ~TRTSDT, ~TRTSDTF, + "03", "Y", ymd("2021-08-21"), ymd("2021-08-21"), ymd("2021-08-10"), NA, + "04", "N", NA, ymd("2021-05-24"), ymd("2021-02-03"), NA + ) %>% + mutate(STUDYID = "AB42") + + death <- event_source( + dataset_name = "adsl", + filter = DTHFL == "Y", + date = DTHDT, + set_values_to = exprs( + EVENTDESC = "DEATH", + SRCDOM = "ADSL", + SRCVAR = "DTHDT" + ) + ) + + lstalv <- censor_source( + dataset_name = "adls", + date = LSTALVDT, + censor = 1, + set_values_to = exprs( + EVENTDESC = "LAST KNOWN ALIVE DATE", + SRCDOM = "ADSL", + SRCVAR = "LSTALVDT" + ) + ) + + expect_snapshot( + derive_param_tte( + dataset_adsl = adsl, + start_date = TRTSDT, + event_conditions = list(death), + censor_conditions = list(lstalv), + source_datasets = list(adsl = adsl), + set_values_to = exprs( + PARAMCD = "OS", + PARAM = "Overall Survival" + ) + ), + error = TRUE) +}) # list_tte_source_objects ---- -## Test 13: error is issued if package does not exist ---- -test_that("list_tte_source_objects Test 13: error is issued if package does not exist", { +## Test 14: error is issued if package does not exist ---- +test_that("list_tte_source_objects Test 14: error is issued if package does not exist", { expect_snapshot( list_tte_source_objects(package = "tte"), error = TRUE ) }) -## Test 14: expected objects produced ---- -test_that("list_tte_source_objects Test 14: expected objects produced", { +## Test 15: expected objects produced ---- +test_that("list_tte_source_objects Test 15: expected objects produced", { expected_output <- tibble::tribble( ~object, ~dataset_name, ~filter, "ae_ser_event", "adae", quote(TRTEMFL == "Y" & AESER == "Y"), From ecd417f136ab464386ab2ebb61af0df5c3124c88 Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss Date: Thu, 10 Oct 2024 15:01:23 +0000 Subject: [PATCH 2/2] #2519 fix_param_tte: style file --- tests/testthat/test-derive_param_tte.R | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-derive_param_tte.R b/tests/testthat/test-derive_param_tte.R index ceb996dba5..34067442da 100644 --- a/tests/testthat/test-derive_param_tte.R +++ b/tests/testthat/test-derive_param_tte.R @@ -917,18 +917,19 @@ test_that("derive_param_tte Test 13: error if dataset_name not in source_datsets ) expect_snapshot( - derive_param_tte( - dataset_adsl = adsl, - start_date = TRTSDT, - event_conditions = list(death), - censor_conditions = list(lstalv), - source_datasets = list(adsl = adsl), - set_values_to = exprs( - PARAMCD = "OS", - PARAM = "Overall Survival" - ) - ), - error = TRUE) + derive_param_tte( + dataset_adsl = adsl, + start_date = TRTSDT, + event_conditions = list(death), + censor_conditions = list(lstalv), + source_datasets = list(adsl = adsl), + set_values_to = exprs( + PARAMCD = "OS", + PARAM = "Overall Survival" + ) + ), + error = TRUE + ) }) # list_tte_source_objects ----