Skip to content

Commit

Permalink
tests: #2595 snapshots for get_summary_records; quiet messages for ot…
Browse files Browse the repository at this point in the history
…her tests
  • Loading branch information
bms63 committed Dec 23, 2024
1 parent 5419517 commit f66b567
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 16 deletions.
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ memory consumption. (#2590)
### Phase 1 (message)

- `derive_param_extreme_record()` is deprecated and replaced by `derive_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()`
- `derive_var_dthcaus()` is deprecated and replaced by `derive_vars_extreme_event()`
- `date_source()` is deprecated and replaced by `derive_vars_extreme_event()`
- `dthcaus_source()` is deprecated and replaced by `derive_vars_extreme_event()`
- `derive_var_extreme_dt()` and `derive_var_extreme_dtm` are deprecated and replaced by `derive_vars_extreme_event()`
- `get_summary_records()` is deprecated. Please use the `dataset_add` argument in `derive_summary_records()`.


### Phase 2 (warning)
Expand Down
2 changes: 0 additions & 2 deletions R/derive_var_extreme_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ 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()",
Expand Down Expand Up @@ -567,7 +566,6 @@ 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()",
Expand Down
10 changes: 10 additions & 0 deletions R/get_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ get_summary_records <- function(dataset,
by_vars,
filter = NULL,
set_values_to = NULL) {
deprecate_inform(
when = "1.2.0",
what = "get_summary_records()",
with = "derive_summary_records()",
details = c(
x = "This message will turn into a warning with release of 1.3.0",
i = "https://pharmaverse.github.io/admiral/reference/derive_summary_records.html"
)
)

assert_vars(by_vars)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
assert_data_frame(
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/get_summary_records.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# get_summary_records Test 1: Summarize average of triplicate ECG interval values

Code
df <- input %>% get_summary_records(by_vars = exprs(USUBJID, PARAM, AVISIT),
set_values_to = exprs(AVAL = mean(AVAL, na.rm = TRUE), DTYPE = "AVERAGE")) %>%
dplyr::mutate(AVAL = round(AVAL))
Message
`get_summary_records()` was deprecated in admiral 1.2.0.
i Please use `derive_summary_records()` instead.
x This message will turn into a warning with release of 1.3.0
i https://pharmaverse.github.io/admiral/reference/derive_summary_records.html

21 changes: 9 additions & 12 deletions tests/testthat/test-derive_var_extreme_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ae <- tibble::tribble(
# derive_var_extreme_dt ----
## Test 1: Message sent to users ----
test_that("derive_var_extreme_dt Test 1: Message sent to users", {

ae_start <- date_source(
dataset_name = "ae",
date = AESTDTM
Expand Down Expand Up @@ -54,8 +53,8 @@ test_that("derive_var_extreme_dt Test 1: Message sent to users", {
source_datasets = list(ae = ae, adsl = adsl),
ae_start, ae_end, adsl_trtdate, adsl_dthdate,
mode = "last"
)
)
)
})

# derive_var_extreme_dt ----
Expand Down Expand Up @@ -168,7 +167,6 @@ test_that("derive_var_extreme_dt Test 4: `NA` dates are excluded", {
# derive_var_extreme_dtm ----
## Test 5: Message sent to users ----
test_that("derive_var_extreme_dtm Test 5: Message sent to users", {

ae_start <- date_source(
dataset_name = "ae",
date = convert_dtc_to_dtm(AESTDTC),
Expand Down Expand Up @@ -210,16 +208,15 @@ test_that("derive_var_extreme_dtm Test 5: Message sent to users", {
)
)

expect_snapshot(
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"
expect_snapshot(
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"
)
)
)

})

# derive_var_extreme_dtm ----
Expand Down
46 changes: 46 additions & 0 deletions tests/testthat/test-get_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,46 @@ test_that("get_summary_records Test 1: Summarize average of triplicate ECG inter
"XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg"
)

expect_snapshot(
df <- input %>%
get_summary_records(
by_vars = exprs(USUBJID, PARAM, AVISIT),
set_values_to = exprs(
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
)
) %>%
dplyr::mutate(AVAL = round(AVAL))
)
})

## Test 1: Summarize the average of the triplicate ECG interval values (AVAL) ----
test_that("get_summary_records Test 1: Summarize average of triplicate ECG interval values", {
# Suppress lifecycle messages within the test environment
withr::local_options(list(lifecycle_verbosity = "quiet"))

input <- tibble::tribble(
~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA,
"XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_,
"XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_,
"XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_,
"XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo",
"XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo",
"XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo",
"XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo",
"XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo",
"XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo",
"XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_,
"XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_,
"XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_,
"XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg",
"XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg",
"XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg",
"XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg",
"XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg",
"XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg"
)

actual_output <- input %>%
get_summary_records(
by_vars = exprs(USUBJID, PARAM, AVISIT),
Expand Down Expand Up @@ -51,6 +91,9 @@ test_that("get_summary_records Test 1: Summarize average of triplicate ECG inter

## Test 2: Derive more than one summary variable ----
test_that("get_summary_records Test 2: Derive more than one summary variable", {
# Suppress lifecycle messages within the test environment
withr::local_options(list(lifecycle_verbosity = "quiet"))

input <- tibble::tribble(
~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA,
"XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_,
Expand Down Expand Up @@ -110,6 +153,9 @@ test_that("get_summary_records Test 2: Derive more than one summary variable", {

## Test 3: Compute avg AVAL only if >2 records within by group ----
test_that("get_summary_records Test 3: Compute avg AVAL only if >2 records within by group", {
# Suppress lifecycle messages within the test environment
withr::local_options(list(lifecycle_verbosity = "quiet"))

input <- tibble::tribble(
~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA,
"XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_,
Expand Down

0 comments on commit f66b567

Please sign in to comment.