Skip to content

Commit

Permalink
tests: #2595 snapshots for inform messages for extreme_data fcns
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Dec 23, 2024
1 parent 4ff7482 commit 5419517
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 84 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ memory consumption. (#2590)
### Phase 1 (message)

- `derive_param_extreme_record()` is deprecated and replaced by `derive_extreme_event()`
- `date_source()` is deprecated and replaced by `derive_vars_extreme_event()`

- `derive_var_dthcaus()` and `dthcaus_source()` are deprecated and replaced by `derive_vars_extreme_event()`
- `derive_var_extreme_dt()` is deprecated and replaced by `derive_vars_extreme_event()`


### Phase 2 (warning)

### Phase 3 (error)
Expand Down
10 changes: 10 additions & 0 deletions R/derive_var_dthcaus.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ derive_var_dthcaus <- function(dataset,
...,
source_datasets,
subject_keys = get_admiral_option("subject_keys")) {
deprecate_inform(
when = "1.2.0",
what = "derive_var_dthcaus()",
with = "derive_vars_extreme_event()",
details = c(
x = "This message will turn into a warning with release of 1.3.0",
i = "https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html"
)
)

assert_vars(subject_keys)
assert_data_frame(dataset, required_vars = subject_keys)
assert_list_of(source_datasets, "data.frame")
Expand Down
23 changes: 23 additions & 0 deletions R/derive_var_extreme_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ derive_var_extreme_dtm <- function(dataset,
source_datasets,
mode,
subject_keys = get_admiral_option("subject_keys")) {

deprecate_inform(
when = "1.2.0",
what = "derive_var_extreme_dtm()",
with = "derive_vars_extreme_event()",
details = c(
x = "This message will turn into a warning with release of 1.3.0",
i = "https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html"
)
)

assert_vars(subject_keys)
assert_data_frame(dataset, required_vars = subject_keys)
new_var <- assert_symbol(enexpr(new_var))
Expand Down Expand Up @@ -556,6 +567,18 @@ derive_var_extreme_dt <- function(dataset,
source_datasets,
mode,
subject_keys = get_admiral_option("subject_keys")) {

deprecate_inform(
when = "1.2.0",
what = "derive_var_extreme_dt()",
with = "derive_vars_extreme_event()",
details = c(
x = "This message will turn into a warning with release of 1.3.0",
i = "https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html"
)
)


new_var <- assert_symbol(enexpr(new_var))

sources <- list(...)
Expand Down
9 changes: 7 additions & 2 deletions tests/testthat/_snaps/derive_var_dthcaus.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# derive_var_dthcaus Test 2: Message sent to users
# derive_var_dthcaus Test 1: Message sent to users

Code
src_ae <- dthcaus_source(dataset_name = "ae", filter = AEOUT == "FATAL", date = AEDTHDT,
Expand All @@ -20,6 +20,11 @@
Code
derive_var_dthcaus(adsl, source_datasets = list(ae = ae, ds = ds), src_ae,
src_ds)
Message
`derive_var_dthcaus()` was deprecated in admiral 1.2.0.
i Please use `derive_vars_extreme_event()` instead.
x This message will turn into a warning with release of 1.3.0
i https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html
Output
# A tibble: 3 x 3
STUDYID USUBJID DTHCAUS
Expand All @@ -28,7 +33,7 @@
2 TEST01 PAT02 <NA>
3 TEST01 PAT03 SUDDEN DEATH

# derive_var_dthcaus Test 11: error if source dataset is not available
# derive_var_dthcaus Test 12: error if source dataset is not available

Code
derive_var_dthcaus(adsl, source_datasets = list(ae = ae, dd = ds), src_ae,
Expand Down
37 changes: 37 additions & 0 deletions tests/testthat/_snaps/derive_var_extreme_date.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# derive_var_extreme_dt Test 1: Message sent to users

Code
derive_var_extreme_dt(adsl, new_var = LSTALVDT, source_datasets = list(ae = ae,
adsl = adsl), ae_start, ae_end, adsl_trtdate, adsl_dthdate, mode = "last")
Message
`derive_var_extreme_dt()` was deprecated in admiral 1.2.0.
i Please use `derive_vars_extreme_event()` instead.
x This message will turn into a warning with release of 1.3.0
i https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html
Output
# A tibble: 3 x 6
STUDYID USUBJID TRTEDTM DTHDTC DTHDT LSTALVDT
<chr> <chr> <dttm> <chr> <date> <date>
1 STUDY01 1 2020-01-01 12:00:00 <NA> NA 2020-02-01
2 STUDY01 2 NA 2020-06 2020-06-01 NA
3 STUDY01 3 2020-04-12 13:15:00 <NA> NA 2020-04-12

# derive_var_extreme_dtm Test 4: Message sent to users

Code
derive_var_extreme_dtm(adsl, new_var = LSTALVDTM, source_datasets = list(ae = ae,
adsl = adsl), ae_start, ae_end, adsl_trtdate, adsl_dthdate, mode = "last")
Message
`derive_var_extreme_dtm()` was deprecated in admiral 1.2.0.
i Please use `derive_vars_extreme_event()` instead.
x This message will turn into a warning with release of 1.3.0
i https://pharmaverse.github.io/admiral/reference/derive_vars_extreme_event.html
Output
# A tibble: 3 x 9
STUDYID USUBJID TRTEDTM DTHDTC DTHDT LALVDOM LALVSEQ LALVVAR
<chr> <chr> <dttm> <chr> <date> <chr> <dbl> <chr>
1 STUDY01 1 2020-01-01 12:00:00 <NA> NA AE 2 AEENDTC
2 STUDY01 2 NA 2020-06 2020-06-01 <NA> NA <NA>
3 STUDY01 3 2020-04-12 13:15:00 <NA> NA ADSL NA TRTEDTM
# i 1 more variable: LSTALVDTM <dttm>

# derive_var_extreme_dtm Test 6: error if source dataset is not available

Code
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-derive_param_extreme_record.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ test_that("derive_param_extreme_record Test 2: Analysis date are derived correct
actual_output,
keys = c("USUBJID", "PARAMCD", "PARAM", "ADT", "AVALC")
)

})

## Test 3: Error given when order variable is not inside source datasets ----
Expand Down
102 changes: 35 additions & 67 deletions tests/testthat/test-derive_var_dthcaus.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("derive_var_dthcaus Test 2: Message sent to users", {
## Test 1: Message sent to users ----
test_that("derive_var_dthcaus Test 1: Message sent to users", {
adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
"TEST01", "PAT01",
Expand Down Expand Up @@ -53,10 +54,10 @@ test_that("derive_var_dthcaus Test 2: Message sent to users", {
})
})

## Test 1: error on invalid mode ----
test_that("dthcaus_source Test 1: error on invalid mode", {
## Test 2: error on invalid mode ----
test_that("derive_var_dthcaus Test 2: error on invalid mode", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

expect_error(dthcaus_source(
dataset_name = "ae",
Expand All @@ -65,16 +66,13 @@ test_that("dthcaus_source Test 1: error on invalid mode", {
mode = "blah",
dthcaus = AEDECOD
))

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

# derive_var_dthcaus ----
## Test 2: DTHCAUS is added from AE and DS ----
test_that("derive_var_dthcaus Test 2: DTHCAUS is added from AE and DS", {
## Test 3: DTHCAUS is added from AE and DS ----
test_that("derive_var_dthcaus Test 3: DTHCAUS is added from AE and DS", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -135,15 +133,12 @@ test_that("derive_var_dthcaus Test 2: DTHCAUS is added from AE and DS", {
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 3: `dthcaus` handles symbols and string literals correctly ----
test_that("derive_var_dthcaus Test 3: `dthcaus` handles symbols and string literals correctly", {
## Test 4: `dthcaus` handles symbols and string literals correctly ----
test_that("derive_var_dthcaus Test 4: `dthcaus` handles symbols and string literals correctly", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -202,15 +197,12 @@ test_that("derive_var_dthcaus Test 3: `dthcaus` handles symbols and string liter
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 4: traceability variables are added from AE and DS ----
test_that("derive_var_dthcaus Test 4: traceability variables are added from AE and DS", {
## Test 5: traceability variables are added from AE and DS ----
test_that("derive_var_dthcaus Test 5: traceability variables are added from AE and DS", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -276,15 +268,12 @@ test_that("derive_var_dthcaus Test 4: traceability variables are added from AE a
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 5: DTHCAUS/traceabiity are added from 2 input datasets ----
test_that("derive_var_dthcaus Test 5: DTHCAUS/traceabiity are added from 2 input datasets", {
## Test 6: DTHCAUS/traceabiity are added from 2 input datasets ----
test_that("derive_var_dthcaus Test 6: DTHCAUS/traceabiity are added from 2 input datasets", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -351,15 +340,12 @@ test_that("derive_var_dthcaus Test 5: DTHCAUS/traceabiity are added from 2 input
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 6: DTHCAUS is added from AE and DS if filter is not specified ----
test_that("derive_var_dthcaus Test 6: DTHCAUS is added from AE and DS if filter is not specified", {
## Test 7: DTHCAUS is added from AE and DS if filter is not specified ----
test_that("derive_var_dthcaus Test 7: DTHCAUS is added from AE and DS if filter is not specified", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

# test based on covr report - the case for unspecified filter has not been tested

Expand Down Expand Up @@ -425,15 +411,12 @@ test_that("derive_var_dthcaus Test 6: DTHCAUS is added from AE and DS if filter
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 7: error on a dthcaus_source object with invalid order ----
test_that("derive_var_dthcaus Test 7: error on a dthcaus_source object with invalid order", {
## Test 8: error on a dthcaus_source object with invalid order ----
test_that("derive_var_dthcaus Test 8: error on a dthcaus_source object with invalid order", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

expect_error(dthcaus_source(
dataset_name = "ae",
Expand All @@ -443,15 +426,12 @@ test_that("derive_var_dthcaus Test 7: error on a dthcaus_source object with inva
mode = "first",
dthcaus = AEDECOD
))

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 8: `dataset` is sorted using the `order` parameter ----
test_that("derive_var_dthcaus Test 8: `dataset` is sorted using the `order` parameter", {
## Test 9: `dataset` is sorted using the `order` parameter ----
test_that("derive_var_dthcaus Test 9: `dataset` is sorted using the `order` parameter", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -511,15 +491,12 @@ test_that("derive_var_dthcaus Test 8: `dataset` is sorted using the `order` para
)

expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 9: multiple observations from different sources ----
test_that("derive_var_dthcaus Test 9: multiple observations from different sources", {
## Test 10: multiple observations from different sources ----
test_that("derive_var_dthcaus Test 10: multiple observations from different sources", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

expected <- tibble::tribble(
~STUDYID, ~USUBJID, ~DTHCAUS,
Expand Down Expand Up @@ -573,15 +550,12 @@ test_that("derive_var_dthcaus Test 9: multiple observations from different sourc
compare = actual,
keys = c("USUBJID")
)

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 10: multiple observations with same date ----
test_that("derive_var_dthcaus Test 10: multiple observations with same date", {
## Test 11: multiple observations with same date ----
test_that("derive_var_dthcaus Test 11: multiple observations with same date", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

expected <- tibble::tribble(
~STUDYID, ~USUBJID, ~DTHCAUS,
Expand Down Expand Up @@ -635,15 +609,12 @@ test_that("derive_var_dthcaus Test 10: multiple observations with same date", {
compare = actual,
keys = c("USUBJID")
)

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})

## Test 11: error if source dataset is not available ----
test_that("derive_var_dthcaus Test 11: error if source dataset is not available", {
## Test 12: error if source dataset is not available ----
test_that("derive_var_dthcaus Test 12: error if source dataset is not available", {
# Suppress lifecycle messages within the test environment
original_verbosity <- options(lifecycle_verbosity = "quiet")
withr::local_options(list(lifecycle_verbosity = "quiet"))

adsl <- tibble::tribble(
~STUDYID, ~USUBJID,
Expand Down Expand Up @@ -698,7 +669,4 @@ test_that("derive_var_dthcaus Test 11: error if source dataset is not available"
),
error = TRUE
)

# Ensure to reset options after tests
on.exit(options(original_verbosity))
})
Loading

0 comments on commit 5419517

Please sign in to comment.