Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2481 bug the result of derive param tte depends on the sort order of the input #2569

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e23388
Added order arguments to censor_source and event_source. Also added s…
ProfessorP-beep Nov 18, 2024
cd52801
Added order argument to tte_source as part of development and error f…
ProfessorP-beep Nov 18, 2024
2727736
Fixed previous erros but still need to address failed tests for Test …
ProfessorP-beep Nov 18, 2024
9e86217
added check_type arg_match to derive_param_tte so user has to input a…
ProfessorP-beep Nov 18, 2024
d97377c
Changed position of signal_duplicate_records function in derive_param…
ProfessorP-beep Nov 18, 2024
fa49a51
lintr changes by removing whitespace.
ProfessorP-beep Nov 18, 2024
01e8f5a
styler fix.
ProfessorP-beep Nov 18, 2024
53457c2
updated NEWS.md with changes to derive_param_tte,. Removed Test 17 fr…
ProfessorP-beep Nov 19, 2024
020c9d7
Merge branch 'main' into 2481-bug-the-result-of-derive_param_tte-depe…
ProfessorP-beep Nov 19, 2024
dccdbe1
changed the signal_duplicate_records within derive_parame_tte to hand…
ProfessorP-beep Nov 19, 2024
8006891
Merge branch '2481-bug-the-result-of-derive_param_tte-depends-on-the-…
ProfessorP-beep Nov 19, 2024
4c95243
added a tryCatch() to filter_date_sources to catch duplicates to addr…
ProfessorP-beep Nov 21, 2024
087c0f3
Moved duplication check to filter_date_sources in tryCatch() and rewr…
ProfessorP-beep Nov 24, 2024
4405868
1. Moved updates in News section to admiral dev section
ProfessorP-beep Dec 3, 2024
21b5a00
Ran styler, lintr fixes, and devtools check.
ProfessorP-beep Dec 3, 2024
ce07ad1
styler changes
ProfessorP-beep Dec 3, 2024
1d4e6b7
accepted snapshots from testthat and addressed bds_tte.Rmd error for …
ProfessorP-beep Dec 3, 2024
22f3f2d
added documentation for order and check_type arguments added to funct…
ProfessorP-beep Dec 3, 2024
47637a5
requested updates to documentation and test script for derive_param_tte
ProfessorP-beep Dec 16, 2024
e882758
corrected documentation and removed rlang from bds_tte.Rmd
ProfessorP-beep Dec 17, 2024
e5c28fc
updated derive_param_tte documentation and added test to derive_param…
ProfessorP-beep Dec 20, 2024
404c949
fixed spelling error
ProfessorP-beep Dec 20, 2024
ae70492
updates to derive_param_tte documentation and test examples.
ProfessorP-beep Dec 23, 2024
34d2fb3
Update NEWS.md
ProfessorP-beep Jan 8, 2025
65c58ee
Merge branch 'main' into 2481-bug-the-result-of-derive_param_tte-depe…
bms63 Jan 9, 2025
2a3cf6c
update to derive_param_tte test, function examples, and documentation.
ProfessorP-beep Jan 9, 2025
dbbb5ab
Merge branch '2481-bug-the-result-of-derive_param_tte-depends-on-the-…
ProfessorP-beep Jan 9, 2025
1cb81bc
snapshots accepted
ProfessorP-beep Jan 9, 2025
2aeaf29
passed local checks. Pushing again
ProfessorP-beep Jan 10, 2025
a95aa68
ran styler
ProfessorP-beep Jan 10, 2025
0a1d621
added "message" as a option for check_type in derive_var_obs_number
ProfessorP-beep Jan 10, 2025
e94e3eb
Update NEWS.md
ProfessorP-beep Jan 11, 2025
9980980
Merge branch 'main' into 2481-bug-the-result-of-derive_param_tte-depe…
bundfussr Jan 13, 2025
961bdbe
#2481: cosmetics
bundfussr Jan 13, 2025
82614e0
#2481: fix lintr
bundfussr Jan 13, 2025
cc777db
Merge branch 'main' into 2481-bug-the-result-of-derive_param_tte-depe…
bms63 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ example, `">2.5 x ULN"` changed to `">2.5"` for grade 3. (#2534)
</details>

# admiral 1.1.1

- `check_type = "warning"` default argument added to `derive_param_tte` with an
`arg_match` function within the function so the user can use a valid input of
`error, message, warning, or none`. `signal_duplicate_records()` has also been
added to the function on lines 394 and 411 to check for uniqueness of records. (#2481)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

- `order()` function has been added to `event_source()` and `censor_source()` and
defaulted to `NULL` to allow sorting of input data. (#2481)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted
again. (#2462)

Expand Down
77 changes: 53 additions & 24 deletions R/derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ derive_param_tte <- function(dataset = NULL,
censor_conditions,
create_datetime = FALSE,
set_values_to,
subject_keys = get_admiral_option("subject_keys")) {
subject_keys = get_admiral_option("subject_keys"),
check_type = "warning") {
# Match check_type to valid admiral options
check_type <- rlang::arg_match(check_type, c("warning", "message", "error", "none"))
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

# checking and quoting #
assert_data_frame(dataset, optional = TRUE)
assert_vars(by_vars, optional = TRUE)
Expand Down Expand Up @@ -373,16 +377,17 @@ derive_param_tte <- function(dataset = NULL,
by_vars = by_vars
)
}

tmp_event <- get_new_tmp_var(dataset)

# determine events #
event_data <- filter_date_sources(
sources = event_conditions,
source_datasets = source_datasets,
by_vars = by_vars,
create_datetime = create_datetime,
subject_keys = subject_keys,
mode = "first"
mode = "first",
check_type = check_type
) %>%
mutate(!!tmp_event := 1L)

Expand All @@ -393,7 +398,8 @@ derive_param_tte <- function(dataset = NULL,
by_vars = by_vars,
create_datetime = create_datetime,
subject_keys = subject_keys,
mode = "last"
mode = "last",
check_type = check_type
) %>%
mutate(!!tmp_event := 0L)

Expand Down Expand Up @@ -436,7 +442,8 @@ derive_param_tte <- function(dataset = NULL,
bind_rows(event_data, censor_data),
by_vars = expr_c(subject_keys, by_vars),
order = exprs(!!tmp_event),
mode = "last"
mode = "last",
check_type = check_type
) %>%
inner_join(
adsl,
Expand Down Expand Up @@ -571,14 +578,16 @@ derive_param_tte <- function(dataset = NULL,
#' by_vars = exprs(AEDECOD),
#' create_datetime = FALSE,
#' subject_keys = get_admiral_option("subject_keys"),
#' mode = "first"
#' mode = "first",
#' check_type = "none"
#' )
filter_date_sources <- function(sources,
source_datasets,
by_vars,
create_datetime = FALSE,
subject_keys,
mode) {
mode,
check_type = "none") {
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
assert_list_of(sources, "tte_source")
assert_list_of(source_datasets, "data.frame")
assert_logical_scalar(create_datetime)
Expand Down Expand Up @@ -613,17 +622,31 @@ filter_date_sources <- function(sources,
var = !!source_date_var,
dataset_name = sources[[i]]$dataset_name
)
data[[i]] <- source_dataset %>%
filter_if(sources[[i]]$filter) %>%
filter_extreme(
order = exprs(!!source_date_var),
by_vars = expr_c(subject_keys, by_vars),
mode = mode,
check_type = "none"
)

# wrap filter_extreme in tryCatch to catch duplicate records and create a message
data[[i]] <- tryCatch(
{
source_dataset %>%
filter_if(sources[[i]]$filter) %>%
arrange(!!!sources[[i]]$order) %>% # Ensure order is applied
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
filter_extreme(
order = exprs(!!source_date_var),
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
by_vars = expr_c(subject_keys, by_vars),
mode = mode,
check_type = check_type
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
)
},
warning = function(wrn) {
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
if (grepl("duplicate records", conditionMessage(wrn))) {
warning(sprintf(
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
"Dataset '%s' contains duplicate records: %s",
sources[[i]]$dataset_name,
conditionMessage(wrn)
), call. = FALSE)
}
return(source_dataset)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
}
)
# add date variable and accompanying variables

if (create_datetime) {
date_derv <- exprs(!!date_var := as_datetime(!!source_date_var))
} else {
Expand All @@ -649,7 +672,7 @@ filter_date_sources <- function(sources,
by_vars = expr_c(subject_keys, by_vars),
order = exprs(!!date_var),
mode = mode,
check_type = "none"
check_type = check_type
)
}

Expand Down Expand Up @@ -793,7 +816,8 @@ tte_source <- function(dataset_name,
filter = NULL,
date,
censor = 0,
set_values_to = NULL) {
set_values_to = NULL,
order = order) {
out <- list(
dataset_name = assert_character_scalar(dataset_name),
filter = assert_filter_cond(enexpr(filter), optional = TRUE),
Expand All @@ -803,7 +827,8 @@ tte_source <- function(dataset_name,
set_values_to,
named = TRUE,
optional = TRUE
)
),
order = order
)
class(out) <- c("tte_source", "source", "list")
out
Expand Down Expand Up @@ -844,13 +869,15 @@ tte_source <- function(dataset_name,
event_source <- function(dataset_name,
filter = NULL,
date,
set_values_to = NULL) {
set_values_to = NULL,
order = NULL) {
out <- tte_source(
dataset_name = assert_character_scalar(dataset_name),
filter = !!enexpr(filter),
date = !!assert_expr(enexpr(date)),
censor = 0,
set_values_to = set_values_to
set_values_to = set_values_to,
order = order
)
class(out) <- c("event_source", class(out))
out
Expand Down Expand Up @@ -891,13 +918,15 @@ censor_source <- function(dataset_name,
filter = NULL,
date,
censor = 1,
set_values_to = NULL) {
set_values_to = NULL,
order = NULL) {
out <- tte_source(
dataset_name = assert_character_scalar(dataset_name),
filter = !!enexpr(filter),
date = !!assert_expr(enexpr(date)),
censor = assert_integer_scalar(censor, subset = "positive"),
set_values_to = set_values_to
set_values_to = set_values_to,
order = order
)
class(out) <- c("censor_source", class(out))
out
Expand Down
3 changes: 2 additions & 1 deletion man/censor_source.Rd

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

3 changes: 2 additions & 1 deletion man/derive_param_tte.Rd

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

8 changes: 7 additions & 1 deletion man/event_source.Rd

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

9 changes: 8 additions & 1 deletion man/tte_source.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/derive_extreme_event.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
Error in `derive_extreme_event()`:
! The dataset names must be included in the list specified for the `source_datasets` argument.
i Following names were provided by `source_datasets`: adhy
i But, `events[[1]]$dataset_name = adyh`
i But, `events[[1]]$dataset_name = adyh`

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/derive_param_tte.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
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`
Error:
! Could not evaluate cli `{}` expression: `source_names`.
Caused by error:
! object 'source_names' not found

# list_tte_source_objects Test 14: error is issued if package does not exist

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/derive_var_dthcaus.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
Error in `derive_var_dthcaus()`:
! The dataset names must be included in the list specified for the `source_datasets` argument.
i Following names were provided by `source_datasets`: ae and dd
i But, `sources[[2]]$dataset_name = ds`
i But, `sources[[2]]$dataset_name = ds`

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/derive_var_merged_ef_msrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
Error in `derive_var_merged_ef_msrc()`:
! The dataset names must be included in the list specified for the `source_datasets` argument.
i Following names were provided by `source_datasets`: cm and pro
i But, `flag_events[[2]]$dataset_name = pr`
i But, `flag_events[[2]]$dataset_name = pr`

Loading
Loading