Skip to content

Commit

Permalink
#2519 fix_param_tte: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bundfussr committed Oct 10, 2024
1 parent bf9ffdd commit a07fe27
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion tests/testthat/_snaps/derive_param_tte.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
53 changes: 49 additions & 4 deletions tests/testthat/test-derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit a07fe27

Please sign in to comment.