Skip to content

Commit

Permalink
requested updates to documentation and test script for derive_param_tte
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfessorP-beep committed Dec 16, 2024
1 parent 22f3f2d commit 47637a5
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 76 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
- Update `ADEG` template to flag `ABLFL` and `ANL01FL` based on `DTYPE == "AVERAGE"` records. (#2561)

## Updates of Existing Functions
- added `message` as option for `check_type` argument in `filter_extreme` function. (#2481)
- added `message` as option for `check_type` argument in `filter_extreme()` function. (#2481)

- Users can now specify how duplicate records are handled in `derive_param_tte` using the `check_type` argument, with options including `"error"`, `"warning"`, `"message"`, or `"none"`, allowing for greater flexibility in managing duplicate data scenarios. (#2481)
- Users can now specify how duplicate records are handled in `derive_param_tte()` using the `check_type` argument, with options including `"error"`, `"warning"`, `"message"`, or `"none"`, allowing for greater flexibility in managing duplicate data scenarios. (#2481)

- `order` argument has been added to `event_source()` and `censor_source()` and
defaulted to `NULL` to allow specifying variables in addition to the date variable. This can be used to ensure the uniqueness of the select records if there is more than one record per date. (#2481)
Expand Down
12 changes: 3 additions & 9 deletions R/derive_merged.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,20 @@
#' *Permitted Values*: named list of expressions, e.g.,
#' `exprs(BASEC = "MISSING", BASE = -1)`
#'
#'
#'
#' If `"warning"` or `"error"` is specified, the specified message is issued
#' if the observations of the (restricted) additional dataset are not unique
#' with respect to the by variables and the order.
#'
#' If the `order` argument is not specified, the `check_type` argument is ignored:
#' if the observations of the (restricted) additional dataset are not unique with respect
#' to the by variables, an error is issued.
#' if the observations of the (restricted) additional dataset are not unique with respect
#' to the by variables, an error is issued.
#'
#' *Permitted Values*: `"none"`, `"warning"`, `"error"`
#'
#' @param check_type Check uniqueness?
#' *Permitted Values*: `"none"`,`"message"`, `"warning"`, `"error"`
#'
#' If `"warning"`, `"message"`, or `"error"` is specified, the specified message is issued
#' if the observations of the input dataset are not unique with respect to the
#' by variables and the order.
#'
#' Default: `"warning"`
#'
#' @param duplicate_msg Message of unique check
#'
#' If the uniqueness check fails, the specified message is displayed.
Expand Down
3 changes: 1 addition & 2 deletions R/derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ derive_param_tte <- function(dataset = NULL,
#' @return A dataset with one observation per subject as described in the
#' "Details" section.
#'
#' @noRd
#' @keywords internal
#'
#' @examples
#' library(tibble)
Expand Down Expand Up @@ -647,7 +647,6 @@ filter_date_sources <- function(sources,
{
source_dataset %>%
filter_if(sources[[i]]$filter) %>%
arrange(!!!sources[[i]]$order) %>% # Ensure order is applied
filter_extreme(
order = expr_c(exprs(!!source_date_var), sources[[i]]$order),
by_vars = expr_c(subject_keys, by_vars),
Expand Down
6 changes: 5 additions & 1 deletion man/derive_var_merged_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/derive_vars_joined.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/derive_vars_merged.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions man/derive_vars_merged_lookup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions man/filter_date_sources.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 47 additions & 47 deletions tests/testthat/test-derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -932,51 +932,8 @@ test_that("derive_param_tte Test 13: error if dataset_name not in source_datsets
)
})

# list_tte_source_objects ----
## 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 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"),
"ae_gr2_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "2"),
"ae_sev_event", "adae", quote(TRTEMFL == "Y" & AESEV == "SEVERE"),
"ae_gr4_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "4"),
"ae_gr3_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "3"),
"lastalive_censor", "adsl", NULL,
"ae_event", "adae", quote(TRTEMFL == "Y"),
"death_event", "adsl", quote(DTHFL == "Y"),
"ae_gr35_event", "adae", quote(TRTEMFL == "Y" & ATOXGR %in% c("3", "4", "5")),
"ae_wd_event", "adae", quote(TRTEMFL == "Y" & AEACN == "DRUG WITHDRAWN"),
"ae_gr1_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "1"),
"ae_gr5_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "5")
) %>%
mutate(
date = case_when(
object == "lastalive_censor" ~ "LSTALVDT",
object == "death_event" ~ "DTHDT",
TRUE ~ "ASTDT"
),
censor = if_else(object == "lastalive_censor", 1, 0),
filter = as.character(filter),
censor = as.integer(censor)
)

observed_output <- list_tte_source_objects(package = "admiral") %>%
select(object, dataset_name, filter, date, censor)

expect_dfs_equal(expected_output, observed_output, keys = c("object"))
})

## Test 15: derive_param_tte detects duplicates when check_type = 'warning' ----
test_that("derive_param_tte detects duplicates in the input datasets via pipeline functions", {
## Test 14: derive_param_tte detects duplicates when check_type = 'warning' ----
test_that("derive_param_tte Test 14: detects duplicates in input datasets via pipeline functions", {
# Define ADSL dataset
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~TRTEDT, ~EOSDT,
Expand Down Expand Up @@ -1033,8 +990,8 @@ test_that("derive_param_tte detects duplicates in the input datasets via pipelin
)
})

## Test 16: derive_param_tte produces consistent results regardless of input sort order ----
test_that("derive_param_tte produces consistent results regardless of input sort order", {
## Test 15: derive_param_tte produces consistent results regardless of input sort order ----
test_that("derive_param_tte Test 15: produces consistent results regardless of input sort order", {
# Define ADSL dataset
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~TRTEDT, ~EOSDT,
Expand Down Expand Up @@ -1100,3 +1057,46 @@ test_that("derive_param_tte produces consistent results regardless of input sort

expect_equal(result_sorted, result_unsorted)
})

# list_tte_source_objects ----
## Test 16: error is issued if package does not exist ----
test_that("list_tte_source_objects Test 16: error is issued if package does not exist", {
expect_snapshot(
list_tte_source_objects(package = "tte"),
error = TRUE
)
})

## Test 17: expected objects produced ----
test_that("list_tte_source_objects Test 17: expected objects produced", {
expected_output <- tibble::tribble(
~object, ~dataset_name, ~filter,
"ae_ser_event", "adae", quote(TRTEMFL == "Y" & AESER == "Y"),
"ae_gr2_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "2"),
"ae_sev_event", "adae", quote(TRTEMFL == "Y" & AESEV == "SEVERE"),
"ae_gr4_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "4"),
"ae_gr3_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "3"),
"lastalive_censor", "adsl", NULL,
"ae_event", "adae", quote(TRTEMFL == "Y"),
"death_event", "adsl", quote(DTHFL == "Y"),
"ae_gr35_event", "adae", quote(TRTEMFL == "Y" & ATOXGR %in% c("3", "4", "5")),
"ae_wd_event", "adae", quote(TRTEMFL == "Y" & AEACN == "DRUG WITHDRAWN"),
"ae_gr1_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "1"),
"ae_gr5_event", "adae", quote(TRTEMFL == "Y" & ATOXGR == "5")
) %>%
mutate(
date = case_when(
object == "lastalive_censor" ~ "LSTALVDT",
object == "death_event" ~ "DTHDT",
TRUE ~ "ASTDT"
),
censor = if_else(object == "lastalive_censor", 1, 0),
filter = as.character(filter),
censor = as.integer(censor)
)

observed_output <- list_tte_source_objects(package = "admiral") %>%
select(object, dataset_name, filter, date, censor)

expect_dfs_equal(expected_output, observed_output, keys = c("object"))
})

0 comments on commit 47637a5

Please sign in to comment.