diff --git a/NAMESPACE b/NAMESPACE index d124dd8876..03c5e208a4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -108,6 +108,7 @@ export(derive_vars_dtm_to_dt) export(derive_vars_dtm_to_tm) export(derive_vars_duration) export(derive_vars_dy) +export(derive_vars_extreme_event) export(derive_vars_joined) export(derive_vars_merged) export(derive_vars_merged_lookup) diff --git a/NEWS.md b/NEWS.md index a10474c544..49cdbd8a01 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## New Features +- Implement `derive_vars_extreme_event()`, which works as `derive_extreme_event()` but adds variables instead of a parameter. (#2138) + - The new function `derive_var_merged_ef_msrc()` is provided to add a flag indicating if one of the conditions in one of multiple source datasets is fulfilled. (#1728) @@ -119,6 +121,14 @@ to order = exprs(my_order_var), ``` +- `create_query_data()` and `derive_vars_query()` updated to rename variables in + query data set as follows: (#2186) + + - `TERMNAME` to `TERMCHAR` + - `TERMID` to `TERMNUM` + + Users need to adjust their `get_terms()` function accordingly. + - The following functions, which were deprecated in previous `{admiral}` versions, have been removed: (#2098) - `derive_param_extreme_event()` - `derive_vars_last_dose()` @@ -140,14 +150,7 @@ order = exprs(my_order_var), - `derive_var_ontrtfl(span_period)` - The `derive_param_extreme_record()` function has been superseded in favor of `derive_extreme_event()`. (#2141) - -- `create_query_data()` and `derive_vars_query()` updated to rename variables in - query data set as follows: (#2186) - - - `TERMNAME` to `TERMCHAR` - - `TERMID` to `TERMNUM` - - Users need to adjust their `get_terms()` function accordingly. +- The functions `derive_var_dthcaus()`, `derive_var_extreme_dt()`, and `derive_var_extreme_dtm()` are superseded in favor of `derive_vars_extreme_event()`. (#2138) ## Documentation diff --git a/R/derive_extreme_event.R b/R/derive_extreme_event.R index f76febb25a..47746a06ef 100644 --- a/R/derive_extreme_event.R +++ b/R/derive_extreme_event.R @@ -16,7 +16,7 @@ #' functions like `all()` or `any()` can be used in `condition`. #' #' For `event_joined()` events the observations are selected by calling -#' `filter_joined`. The `condition` field is passed to the `filter` argument. +#' `filter_joined()`. The `condition` field is passed to the `filter_join` argument. #' #' @param tmp_event_nr_var Temporary event number variable #' @@ -111,7 +111,7 @@ #' @family der_prm_bds_findings #' @keywords der_prm_bds_findings #' -#' @seealso [event()], [event_joined()] +#' @seealso [event()], [event_joined()], [derive_vars_extreme_event()] #' #' @export #' @@ -340,25 +340,22 @@ #' ) %>% #' filter(PARAMCD == "CBOR") #' -derive_extreme_event <- function(dataset, +derive_extreme_event <- function(dataset = NULL, by_vars = NULL, events, tmp_event_nr_var = NULL, order, mode, source_datasets = NULL, - ignore_event_order = FALSE, + ignore_event_order = NULL, check_type = "warning", - set_values_to, + set_values_to = NULL, keep_source_vars = exprs(everything())) { # Check input parameters + assert_data_frame(dataset, optional = TRUE) assert_vars(by_vars, optional = TRUE) assert_list_of(events, "event_def") assert_expr_list(order) - assert_data_frame( - dataset, - required_vars = by_vars - ) mode <- assert_character_scalar(mode, values = c("first", "last"), case_sensitive = FALSE) assert_list_of(source_datasets, "data.frame") source_names <- names(source_datasets) @@ -378,8 +375,7 @@ derive_extreme_event <- function(dataset, ) } - if (!missing(ignore_event_order)) { - assert_logical_scalar(ignore_event_order) + if (!is.null(ignore_event_order)) { if (ignore_event_order) { deprecate_details <- paste( "The event order is ignored by default.", @@ -407,7 +403,7 @@ derive_extreme_event <- function(dataset, values = c("none", "warning", "error"), case_sensitive = FALSE ) - assert_varval_list(set_values_to) + assert_varval_list(set_values_to, optional = TRUE) keep_source_vars <- assert_expr_list(keep_source_vars) # Create new observations @@ -486,389 +482,3 @@ derive_extreme_event <- function(dataset, # Create output dataset bind_rows(dataset, new_obs) } - -#' Create a `event` Object -#' -#' The `event` object is used to define events as input for the -#' `derive_extreme_event()` function. -#' -#' @param dataset_name Dataset name of the dataset to be used as input for the -#' event. The name refers to the dataset specified for `source_datasets` in -#' `derive_extreme_event()`. If the argument is not specified, the input -#' dataset (`dataset`) of `derive_extreme_event()` is used. -#' -#' *Permitted Values*: a character scalar -#' -#' @param condition An unquoted condition for selecting the observations, which -#' will contribute to the extreme event. If the condition contains summary -#' functions like `all()`, they are evaluated for each by group separately. -#' -#' *Permitted Values*: an unquoted condition -#' -#' @param mode If specified, the first or last observation with respect to `order` is -#' selected for each by group. -#' -#' *Permitted Values*: `"first"`, `"last"`, `NULL` -#' -#' @param order The specified variables or expressions are used to select the -#' first or last observation if `mode` is specified. -#' -#' *Permitted Values*: list of expressions created by `exprs()`, e.g., -#' `exprs(ADT, desc(AVAL))` or `NULL` -#' -#' @param set_values_to A named list returned by `exprs()` defining the variables -#' to be set for the event, e.g. `exprs(PARAMCD = "WSP", -#' PARAM = "Worst Sleeping Problems")`. The values can be a symbol, a -#' character string, a numeric value, `NA` or an expression. -#' -#' *Permitted Values*: a named list of expressions, e.g., created by `exprs()` -#' -#' @param keep_source_vars Variables to keep from the source dataset -#' -#' The specified variables are kept for the selected observations. The -#' variables specified for `by_vars` (of `derive_extreme_event()`) and created -#' by `set_values_to` are always kept. -#' -#' *Permitted Values*: A list of expressions where each element is -#' a symbol or a tidyselect expression, e.g., `exprs(VISIT, VISITNUM, -#' starts_with("RS"))`. -#' -#' @param description Description of the event -#' -#' The description does not affect the derivations where the event is used. It -#' is intended for documentation only. -#' -#' *Permitted Values*: a character scalar -#' -#' @keywords source_specifications -#' @family source_specifications -#' -#' @seealso [derive_extreme_event()], [event_joined()] -#' -#' @export -#' -#' @return An object of class `event` -event <- function(dataset_name = NULL, - condition = NULL, - mode = NULL, - order = NULL, - set_values_to = NULL, - keep_source_vars = NULL, - description = NULL) { - out <- list( - description = assert_character_scalar(description, optional = TRUE), - dataset_name = assert_character_scalar(dataset_name, optional = TRUE), - condition = assert_filter_cond(enexpr(condition), optional = TRUE), - mode = assert_character_scalar( - mode, - values = c("first", "last"), - case_sensitive = FALSE, - optional = TRUE - ), - order = assert_expr_list(order, optional = TRUE), - set_values_to = assert_expr_list( - set_values_to, - named = TRUE, - optional = TRUE - ), - keep_source_vars = assert_expr_list(keep_source_vars, optional = TRUE) - ) - class(out) <- c("event", "event_def", "source", "list") - out -} - -#' Create a `event_joined` Object -#' -#' @description -#' -#' The `event_joined` object is used to define events as input for the -#' `derive_extreme_event()` function. This object should be used if the event -#' does not depend on a single observation of the source dataset but on multiple -#' observations. For example, if the event needs to be confirmed by a second -#' observation of the source dataset. -#' -#' The events are selected by calling `filter_joined()`. See its documentation -#' for more details. -#' -#' @param dataset_name Dataset name of the dataset to be used as input for the -#' event. The name refers to the dataset specified for `source_datasets` in -#' `derive_extreme_event()`. If the argument is not specified, the input -#' dataset (`dataset`) of `derive_extreme_event()` is used. -#' -#' *Permitted Values*: a character scalar -#' -#' @param condition An unquoted condition for selecting the observations, which -#' will contribute to the extreme event. -#' -#' The condition is applied to the joined dataset for selecting the confirmed -#' observations. The condition can include summary functions like `all()` or -#' `any()`. The joined dataset is grouped by the original observations. I.e., -#' the summary function are applied to all observations up to the confirmation -#' observation. For example in the oncology setting when using this function -#' for confirmed best overall response, `condition = AVALC == "CR" & -#' all(AVALC.join %in% c("CR", "NE")) & count_vals(var = AVALC.join, val = -#' "NE") <= 1` selects observations with response "CR" and for all -#' observations up to the confirmation observation the response is "CR" or -#' "NE" and there is at most one "NE". -#' -#' *Permitted Values*: an unquoted condition -#' -#' @param join_vars Variables to keep from joined dataset -#' -#' The variables needed from the other observations should be specified for -#' this parameter. The specified variables are added to the joined dataset -#' with suffix ".join". For example to select all observations with `AVALC == -#' "Y"` and `AVALC == "Y"` for at least one subsequent visit `join_vars = -#' exprs(AVALC, AVISITN)` and `condition = AVALC == "Y" & AVALC.join == "Y" & -#' AVISITN < AVISITN.join` could be specified. -#' -#' The `*.join` variables are not included in the output dataset. -#' -#' *Permitted Values*: a named list of expressions, e.g., created by `exprs()` -#' -#' @param join_type Observations to keep after joining -#' -#' The argument determines which of the joined observations are kept with -#' respect to the original observation. For example, if `join_type = -#' "after"` is specified all observations after the original observations are -#' kept. -#' -#' *Permitted Values:* `"before"`, `"after"`, `"all"` -#' -#' @param first_cond Condition for selecting range of data -#' -#' `r lifecycle::badge("deprecated")` -#' -#' This argument is *deprecated*, please use `first_cond_upper` instead. -#' -#' If this argument is specified, the other observations are restricted up to -#' the first observation where the specified condition is fulfilled. If the -#' condition is not fulfilled for any of the subsequent observations, all -#' observations are removed. -#' -#' *Permitted Values*: an unquoted condition -#' -#' @param first_cond_lower Condition for selecting range of data (before) -#' -#' If this argument is specified, the other observations are restricted from -#' the first observation before the current observation where the specified -#' condition is fulfilled up to the current observation. If the condition is -#' not fulfilled for any of the other observations, no observations are -#' considered, i.e., the observation is not flagged. -#' -#' This parameter should be specified if `condition` contains summary -#' functions which should not apply to all observations but only from a -#' certain observation before the current observation up to the current -#' observation. -#' -#' *Permitted Values*: an unquoted condition -#' -#' @param first_cond_upper Condition for selecting range of data (after) -#' -#' If this argument is specified, the other observations are restricted up to -#' the first observation where the specified condition is fulfilled. If the -#' condition is not fulfilled for any of the other observations, no -#' observations are considered, i.e., the observation is not flagged. -#' -#' This parameter should be specified if `condition` contains summary -#' functions which should not apply to all observations but only up to the -#' confirmation assessment. -#' -#' *Permitted Values*: an unquoted condition -#' -#' @param order If specified, the specified variables or expressions are used to -#' select the first observation. -#' -#' *Permitted Values*: list of expressions created by `exprs()`, e.g., -#' `exprs(ADT, desc(AVAL))` or `NULL` -#' -#' @inheritParams event -#' -#' @return An object of class `event_joined` -#' -#' @keywords source_specifications -#' @family source_specifications -#' -#' @seealso [derive_extreme_event()], [event()] -#' -#' @export -#' -#' @examples -#' library(tibble) -#' library(dplyr) -#' library(lubridate) -#' # Derive confirmed best overall response (using event_joined()) -#' # CR - complete response, PR - partial response, SD - stable disease -#' # NE - not evaluable, PD - progressive disease -#' adsl <- tribble( -#' ~USUBJID, ~TRTSDTC, -#' "1", "2020-01-01", -#' "2", "2019-12-12", -#' "3", "2019-11-11", -#' "4", "2019-12-30", -#' "5", "2020-01-01", -#' "6", "2020-02-02", -#' "7", "2020-02-02", -#' "8", "2020-02-01" -#' ) %>% -#' mutate(TRTSDT = ymd(TRTSDTC)) -#' -#' adrs <- tribble( -#' ~USUBJID, ~ADTC, ~AVALC, -#' "1", "2020-01-01", "PR", -#' "1", "2020-02-01", "CR", -#' "1", "2020-02-16", "NE", -#' "1", "2020-03-01", "CR", -#' "1", "2020-04-01", "SD", -#' "2", "2020-01-01", "SD", -#' "2", "2020-02-01", "PR", -#' "2", "2020-03-01", "SD", -#' "2", "2020-03-13", "CR", -#' "4", "2020-01-01", "PR", -#' "4", "2020-03-01", "NE", -#' "4", "2020-04-01", "NE", -#' "4", "2020-05-01", "PR", -#' "5", "2020-01-01", "PR", -#' "5", "2020-01-10", "PR", -#' "5", "2020-01-20", "PR", -#' "6", "2020-02-06", "PR", -#' "6", "2020-02-16", "CR", -#' "6", "2020-03-30", "PR", -#' "7", "2020-02-06", "PR", -#' "7", "2020-02-16", "CR", -#' "7", "2020-04-01", "NE", -#' "8", "2020-02-16", "PD" -#' ) %>% -#' mutate( -#' ADT = ymd(ADTC), -#' PARAMCD = "OVR", -#' PARAM = "Overall Response by Investigator" -#' ) %>% -#' derive_vars_merged( -#' dataset_add = adsl, -#' by_vars = exprs(USUBJID), -#' new_vars = exprs(TRTSDT) -#' ) -#' -#' derive_extreme_event( -#' adrs, -#' by_vars = exprs(USUBJID), -#' order = exprs(ADT), -#' mode = "first", -#' source_datasets = list(adsl = adsl), -#' events = list( -#' event_joined( -#' description = paste( -#' "CR needs to be confirmed by a second CR at least 28 days later", -#' "at most one NE is acceptable between the two assessments" -#' ), -#' join_vars = exprs(AVALC, ADT), -#' join_type = "after", -#' first_cond_upper = AVALC.join == "CR" & -#' ADT.join >= ADT + 28, -#' condition = AVALC == "CR" & -#' all(AVALC.join %in% c("CR", "NE")) & -#' count_vals(var = AVALC.join, val = "NE") <= 1, -#' set_values_to = exprs( -#' AVALC = "CR" -#' ) -#' ), -#' event_joined( -#' description = paste( -#' "PR needs to be confirmed by a second CR or PR at least 28 days later,", -#' "at most one NE is acceptable between the two assessments" -#' ), -#' join_vars = exprs(AVALC, ADT), -#' join_type = "after", -#' first_cond_upper = AVALC.join %in% c("CR", "PR") & -#' ADT.join >= ADT + 28, -#' condition = AVALC == "PR" & -#' all(AVALC.join %in% c("CR", "PR", "NE")) & -#' count_vals(var = AVALC.join, val = "NE") <= 1, -#' set_values_to = exprs( -#' AVALC = "PR" -#' ) -#' ), -#' event( -#' description = paste( -#' "CR, PR, or SD are considered as SD if occurring at least 28", -#' "after treatment start" -#' ), -#' condition = AVALC %in% c("CR", "PR", "SD") & ADT >= TRTSDT + 28, -#' set_values_to = exprs( -#' AVALC = "SD" -#' ) -#' ), -#' event( -#' condition = AVALC == "PD", -#' set_values_to = exprs( -#' AVALC = "PD" -#' ) -#' ), -#' event( -#' condition = AVALC %in% c("CR", "PR", "SD", "NE"), -#' set_values_to = exprs( -#' AVALC = "NE" -#' ) -#' ), -#' event( -#' description = "set response to MISSING for patients without records in ADRS", -#' dataset_name = "adsl", -#' condition = TRUE, -#' set_values_to = exprs( -#' AVALC = "MISSING" -#' ), -#' keep_source_vars = exprs(TRTSDT) -#' ) -#' ), -#' set_values_to = exprs( -#' PARAMCD = "CBOR", -#' PARAM = "Best Confirmed Overall Response by Investigator" -#' ) -#' ) %>% -#' filter(PARAMCD == "CBOR") -event_joined <- function(dataset_name = NULL, - condition, - order = NULL, - join_vars, - join_type, - first_cond = NULL, - first_cond_lower = NULL, - first_cond_upper = NULL, - set_values_to = NULL, - keep_source_vars = NULL, - description = NULL) { - if (!missing(first_cond)) { - deprecate_warn( - "1.0.0", - "event_joined(first_cond=)", - "event_joined(first_cond_upper=)" - ) - first_cond_upper <- assert_filter_cond(enexpr(first_cond), optional = TRUE) - } else { - first_cond_upper <- assert_filter_cond(enexpr(first_cond_upper), optional = TRUE) - } - - out <- list( - description = assert_character_scalar(description, optional = TRUE), - dataset_name = assert_character_scalar(dataset_name, optional = TRUE), - condition = assert_filter_cond(enexpr(condition), optional = TRUE), - order = assert_expr_list(order, optional = TRUE), - join_vars = assert_vars(join_vars), - join_type = assert_character_scalar( - join_type, - values = c("before", "after", "all"), - case_sensitive = FALSE - ), - first_cond_lower = assert_filter_cond(enexpr(first_cond_lower), optional = TRUE), - first_cond_upper = first_cond_upper, - set_values_to = assert_expr_list( - set_values_to, - named = TRUE, - optional = TRUE - ), - keep_source_vars = assert_expr_list(keep_source_vars, optional = TRUE) - ) - class(out) <- c("event_joined", "event_def", "source", "list") - out -} diff --git a/R/derive_var_dthcaus.R b/R/derive_var_dthcaus.R index e0e0bceca2..4bccb790e7 100644 --- a/R/derive_var_dthcaus.R +++ b/R/derive_var_dthcaus.R @@ -1,5 +1,9 @@ #' Derive Death Cause #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_var_dthcaus()` +#' function has been superseded in favor of `derive_vars_extreme_event()`. +#' #' Derive death cause (`DTHCAUS`) and add traceability variables if required. #' #' @param dataset @@ -22,8 +26,8 @@ #' equivalent, the first source will be kept, so the user should provide the inputs in #' the preferred order. #' -#' @family der_adsl -#' @keywords der_adsl +#' @family superseded +#' @keywords superseded #' #' @return The input dataset with `DTHCAUS` variable added. #' @@ -237,6 +241,11 @@ derive_var_dthcaus <- function(dataset, #' Create a `dthcaus_source` Object #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_var_dthcaus()` +#' function and `dthcaus_source()` have been superseded in favor of +#' `derive_vars_extreme_event()`. +#' #' @param dataset_name The name of the dataset, i.e. a string, used to search for #' the death cause. #' @@ -279,8 +288,8 @@ derive_var_dthcaus <- function(dataset, #' #' @param set_values_to Variables to be set to trace the source dataset #' -#' @keywords source_specifications -#' @family source_specifications +#' @family superseded +#' @keywords superseded #' #' #' @export diff --git a/R/derive_var_extreme_date.R b/R/derive_var_extreme_date.R index c4611189c6..2bc266d288 100644 --- a/R/derive_var_extreme_date.R +++ b/R/derive_var_extreme_date.R @@ -1,5 +1,9 @@ #' Derive First or Last Datetime from Multiple Sources #' +#' @description +#' `r lifecycle::badge("superseded")` The `derive_var_extreme_dtm()` +#' function has been superseded in favor of `derive_vars_extreme_event()`. +#' #' Add the first or last datetime from multiple sources to the dataset, e.g., #' the last known alive datetime (`LSTALVDTM`). #' @@ -49,8 +53,8 @@ #' @return The input dataset with the new variable added. #' #' -#' @family der_adsl -#' @keywords der_adsl +#' @family superseded +#' @keywords superseded #' #' @seealso [date_source()], [derive_var_extreme_dt()], #' [derive_vars_merged()] @@ -332,7 +336,11 @@ derive_var_extreme_dtm <- function(dataset, #' Derive First or Last Date from Multiple Sources #' -#' @description Add the first or last date from multiple sources to the +#' @description +#' `r lifecycle::badge("superseded")` The `derive_var_extreme_dt()` +#' function has been superseded in favor of `derive_vars_extreme_event()`. +#' +#' Add the first or last date from multiple sources to the #' dataset, e.g., the last known alive date (`LSTALVDT`). #' #' **Note:** This is a wrapper function for the function `derive_var_extreme_dtm()`. @@ -363,8 +371,8 @@ derive_var_extreme_dtm <- function(dataset, #' @return The input dataset with the new variable added. #' #' -#' @family der_adsl -#' @keywords der_adsl +#' @family superseded +#' @keywords superseded #' #' @seealso [date_source()], [derive_var_extreme_dtm()], [derive_vars_merged()] #' @@ -561,6 +569,10 @@ derive_var_extreme_dt <- function(dataset, #' Create a `date_source` object #' +#' @description +#' `r lifecycle::badge("superseded")` The `date_source()` +#' function has been superseded in favor of `derive_vars_extreme_event()`. +#' #' Create a `date_source` object as input for `derive_var_extreme_dt()` and #' `derive_var_extreme_dtm()`. #' @@ -583,8 +595,8 @@ derive_var_extreme_dt <- function(dataset, #' #' @seealso [derive_var_extreme_dtm()], [derive_var_extreme_dt()] #' -#' @family source_specifications -#' @keywords source_specifications +#' @family superseded +#' @keywords superseded #' #' @export #' diff --git a/R/derive_vars_extreme_event.R b/R/derive_vars_extreme_event.R new file mode 100644 index 0000000000..df123cdbfa --- /dev/null +++ b/R/derive_vars_extreme_event.R @@ -0,0 +1,227 @@ +#' Add the Worst or Best Observation for Each By Group as New Variables +#' +#' Add the first available record from `events` for each by group as new +#' variables, all variables of the selected observation are kept. It can be used +#' for selecting the extreme observation from a series of user-defined events. +#' +#' @param events Conditions and new values defining events +#' +#' A list of `event()` or `event_joined()` objects is expected. Only +#' observations listed in the `events` are considered for deriving extreme +#' event. If multiple records meet the filter `condition`, take the first +#' record sorted by `order`. The data is grouped by `by_vars`, i.e., summary +#' functions like `all()` or `any()` can be used in `condition`. +#' +#' For `event_joined()` events the observations are selected by calling +#' `filter_joined()`. The `condition` field is passed to the `filter_join` argument. +#' +#' @param tmp_event_nr_var Temporary event number variable +#' +#' The specified variable is added to all source datasets and is set to the +#' number of the event before selecting the records of the event. +#' +#' It can be used in `order` to determine which record should be used if +#' records from more than one event are selected. +#' +#' The variable is not included in the output dataset. +#' +#' @param order Sort order +#' +#' If a particular event from `events` has more than one observation, within +#' the event and by group, the records are ordered by the specified order. +#' +#' *Permitted Values:* list of expressions created by `exprs()`, e.g., +#' `exprs(ADT, desc(AVAL))` +#' +#' @param mode Selection mode (first or last) +#' +#' If a particular event from `events` has more than one observation, +#' `"first"`/`"last"` is used to select the first/last record of this type of +#' event sorting by `order`. +#' +#' *Permitted Values:* `"first"`, `"last"` +#' +#' @param source_datasets Source datasets +#' +#' A named list of datasets is expected. The `dataset_name` field of `event()` +#' and `event_joined()` refers to the dataset provided in the list. +#' +#' @param new_vars Variables to add +#' +#' The specified variables from the events are added to the output +#' dataset. Variables can be renamed by naming the element, i.e., `new_vars = +#' exprs( = )`. +#' +#' @inheritParams filter_extreme +#' @inheritParams derive_summary_records +#' +#' @details +#' 1. For each event select the observations to consider: +#' +#' 1. If the event is of class `event`, the observations of the source dataset +#' are restricted by `condition` and then the first or last (`mode`) +#' observation per by group (`by_vars`) is selected. +#' +#' If the event is of class `event_joined`, `filter_joined()` is called to +#' select the observations. +#' +#' 1. The variables specified by the `set_values_to` field of the event +#' are added to the selected observations. +#' 1. The variable specified for `tmp_event_nr_var` is added and set to +#' the number of the event. +#' 1. All selected observations are bound together. +#' 1. For each group (with respect to the variables specified for the +#' `by_vars` parameter) the first or last observation (with respect to the +#' order specified for the `order` parameter and the mode specified for the +#' `mode` parameter) is selected. +#' 1. The variables specified by the `new_vars` parameter are added to +#' the selected observations. +#' 1. The variables are added to input dataset. +#' +#' +#' @return The input dataset with the best or worst observation of each by group +#' added as new variables. +#' +#' @family der_adsl +#' @keywords der_adsl +#' +#' @seealso [event()], [event_joined()], [derive_extreme_event()] +#' +#' @export +#' +#' @examples +#' library(tibble) +#' library(dplyr) +#' library(lubridate) +#' +#' adsl <- tribble( +#' ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, +#' "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), +#' "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), +#' "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), +#' "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), +#' "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), +#' ) +#' +#' lb <- tribble( +#' ~STUDYID, ~DOMAIN, ~USUBJID, ~LBSEQ, ~LBDTC, +#' "PILOT01", "LB", "01-1130", 219, "2014-06-07T13:20", +#' "PILOT01", "LB", "01-1130", 322, "2014-08-16T13:10", +#' "PILOT01", "LB", "01-1133", 268, "2013-04-18T15:30", +#' "PILOT01", "LB", "01-1133", 304, "2013-05-01T10:13", +#' "PILOT01", "LB", "01-1211", 8, "2012-10-30T14:26", +#' "PILOT01", "LB", "01-1211", 162, "2013-01-08T12:13", +#' "PILOT01", "LB", "09-1081", 47, "2014-02-01T10:55", +#' "PILOT01", "LB", "09-1081", 219, "2014-05-10T11:15", +#' "PILOT01", "LB", "09-1088", 283, "2014-09-27T12:13", +#' "PILOT01", "LB", "09-1088", 322, "2014-10-09T13:25" +#' ) %>% +#' mutate( +#' ADT = convert_dtc_to_dt(LBDTC) +#' ) +#' +#' derive_vars_extreme_event( +#' adsl, +#' by_vars = exprs(STUDYID, USUBJID), +#' events = list( +#' event( +#' dataset_name = "adsl", +#' condition = !is.na(DTHDT), +#' set_values_to = exprs(LSTALVDT = DTHDT, DTHFL = "Y") +#' ), +#' event( +#' dataset_name = "lb", +#' condition = !is.na(ADT), +#' order = exprs(ADT), +#' mode = "last", +#' set_values_to = exprs(LSTALVDT = ADT, DTHFL = "N") +#' ), +#' event( +#' dataset_name = "adsl", +#' condition = !is.na(TRTEDT), +#' order = exprs(TRTEDT), +#' mode = "last", +#' set_values_to = exprs(LSTALVDT = TRTEDT, DTHFL = "N") +#' ) +#' ), +#' source_datasets = list(adsl = adsl, lb = lb), +#' tmp_event_nr_var = event_nr, +#' order = exprs(LSTALVDT, event_nr), +#' mode = "last", +#' new_vars = exprs(LSTALVDT, DTHFL) +#' ) +#' +#' # Derive DTHCAUS from AE and DS domain data +#' adsl <- tribble( +#' ~STUDYID, ~USUBJID, +#' "STUDY01", "PAT01", +#' "STUDY01", "PAT02", +#' "STUDY01", "PAT03" +#' ) +#' ae <- tribble( +#' ~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC, +#' "STUDY01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-04", +#' "STUDY01", "PAT01", 13, "CARDIAC ARREST", "FATAL", "2021-04-03", +#' ) +#' +#' ds <- tribble( +#' ~STUDYID, ~USUBJID, ~DSSEQ, ~DSDECOD, ~DSTERM, ~DSSTDTC, +#' "STUDY01", "PAT02", 1, "INFORMED CONSENT OBTAINED", "INFORMED CONSENT OBTAINED", "2021-04-03", +#' "STUDY01", "PAT02", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11", +#' "STUDY01", "PAT02", 3, "DEATH", "DEATH DUE TO PROGRESSION OF DISEASE", "2022-02-01", +#' "STUDY01", "PAT03", 1, "DEATH", "POST STUDY REPORTING OF DEATH", "2022-03-03" +#' ) +#' +#' derive_vars_extreme_event( +#' adsl, +#' by_vars = exprs(STUDYID, USUBJID), +#' events = list( +#' event( +#' dataset_name = "ae", +#' condition = AEOUT == "FATAL", +#' set_values_to = exprs(DTHCAUS = AEDECOD, DTHDT = convert_dtc_to_dt(AEDTHDTC)), +#' order = exprs(DTHDT) +#' ), +#' event( +#' dataset_name = "ds", +#' condition = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), +#' set_values_to = exprs(DTHCAUS = DSTERM, DTHDT = convert_dtc_to_dt(DSSTDTC)), +#' order = exprs(DTHDT) +#' ) +#' ), +#' source_datasets = list(ae = ae, ds = ds), +#' tmp_event_nr_var = event_nr, +#' order = exprs(DTHDT, event_nr), +#' mode = "first", +#' new_vars = exprs(DTHCAUS, DTHDT) +#' ) +derive_vars_extreme_event <- function(dataset, + by_vars = NULL, + events, + tmp_event_nr_var = NULL, + order, + mode, + source_datasets = NULL, + check_type = "warning", + new_vars) { + assert_expr_list(new_vars) + tmp_event_nr_var <- assert_symbol(enexpr(tmp_event_nr_var), optional = TRUE) + + new_obs <- derive_extreme_event( + dataset = NULL, + by_vars = by_vars, + events = events, + tmp_event_nr_var = !!tmp_event_nr_var, + order = order, + mode = mode, + source_datasets = source_datasets, + check_type = check_type + ) + + derive_vars_merged( + dataset, + dataset_add = new_obs, + new_vars = new_vars, + by_vars = by_vars + ) +} diff --git a/R/event.R b/R/event.R new file mode 100644 index 0000000000..5e98693cfc --- /dev/null +++ b/R/event.R @@ -0,0 +1,386 @@ +#' Create a `event` Object +#' +#' The `event` object is used to define events as input for the +#' `derive_extreme_event()` and `derive_vars_extreme_event()` functions. +#' +#' @param dataset_name Dataset name of the dataset to be used as input for the +#' event. The name refers to the dataset specified for `source_datasets` in +#' `derive_extreme_event()`. If the argument is not specified, the input +#' dataset (`dataset`) of `derive_extreme_event()` is used. +#' +#' *Permitted Values*: a character scalar +#' +#' @param condition An unquoted condition for selecting the observations, which +#' will contribute to the extreme event. If the condition contains summary +#' functions like `all()`, they are evaluated for each by group separately. +#' +#' *Permitted Values*: an unquoted condition +#' +#' @param mode If specified, the first or last observation with respect to `order` is +#' selected for each by group. +#' +#' *Permitted Values*: `"first"`, `"last"`, `NULL` +#' +#' @param order The specified variables or expressions are used to select the +#' first or last observation if `mode` is specified. +#' +#' *Permitted Values*: list of expressions created by `exprs()`, e.g., +#' `exprs(ADT, desc(AVAL))` or `NULL` +#' +#' @param set_values_to A named list returned by `exprs()` defining the variables +#' to be set for the event, e.g. `exprs(PARAMCD = "WSP", +#' PARAM = "Worst Sleeping Problems")`. The values can be a symbol, a +#' character string, a numeric value, `NA` or an expression. +#' +#' *Permitted Values*: a named list of expressions, e.g., created by `exprs()` +#' +#' @param keep_source_vars Variables to keep from the source dataset +#' +#' The specified variables are kept for the selected observations. The +#' variables specified for `by_vars` (of `derive_extreme_event()`) and created +#' by `set_values_to` are always kept. +#' +#' *Permitted Values*: A list of expressions where each element is +#' a symbol or a tidyselect expression, e.g., `exprs(VISIT, VISITNUM, +#' starts_with("RS"))`. +#' +#' @param description Description of the event +#' +#' The description does not affect the derivations where the event is used. It +#' is intended for documentation only. +#' +#' *Permitted Values*: a character scalar +#' +#' @keywords source_specifications +#' @family source_specifications +#' +#' @seealso [derive_extreme_event()], [derive_vars_extreme_event()], [event_joined()] +#' +#' @export +#' +#' @return An object of class `event` +event <- function(dataset_name = NULL, + condition = NULL, + mode = NULL, + order = NULL, + set_values_to = NULL, + keep_source_vars = NULL, + description = NULL) { + out <- list( + description = assert_character_scalar(description, optional = TRUE), + dataset_name = assert_character_scalar(dataset_name, optional = TRUE), + condition = assert_filter_cond(enexpr(condition), optional = TRUE), + mode = assert_character_scalar( + mode, + values = c("first", "last"), + case_sensitive = FALSE, + optional = TRUE + ), + order = assert_expr_list(order, optional = TRUE), + set_values_to = assert_expr_list( + set_values_to, + named = TRUE, + optional = TRUE + ), + keep_source_vars = assert_expr_list(keep_source_vars, optional = TRUE) + ) + class(out) <- c("event", "event_def", "source", "list") + out +} + +#' Create a `event_joined` Object +#' +#' @description +#' +#' The `event_joined` object is used to define events as input for the +#' `derive_extreme_event()` and `derive_vars_extreme_event()` functions. +#' This object should be used if the event does not depend on a single +#' observation of the source dataset but on multiple observations. For example, +#' if the event needs to be confirmed by a second observation of the source +#' dataset. +#' +#' The events are selected by calling `filter_joined()`. See its documentation +#' for more details. +#' +#' @param dataset_name Dataset name of the dataset to be used as input for the +#' event. The name refers to the dataset specified for `source_datasets` in +#' `derive_extreme_event()`. If the argument is not specified, the input +#' dataset (`dataset`) of `derive_extreme_event()` is used. +#' +#' *Permitted Values*: a character scalar +#' +#' @param condition An unquoted condition for selecting the observations, which +#' will contribute to the extreme event. +#' +#' The condition is applied to the joined dataset for selecting the confirmed +#' observations. The condition can include summary functions like `all()` or +#' `any()`. The joined dataset is grouped by the original observations. I.e., +#' the summary function are applied to all observations up to the confirmation +#' observation. For example in the oncology setting when using this function +#' for confirmed best overall response, `condition = AVALC == "CR" & +#' all(AVALC.join %in% c("CR", "NE")) & count_vals(var = AVALC.join, val = +#' "NE") <= 1` selects observations with response "CR" and for all +#' observations up to the confirmation observation the response is "CR" or +#' "NE" and there is at most one "NE". +#' +#' *Permitted Values*: an unquoted condition +#' +#' @param join_vars Variables to keep from joined dataset +#' +#' The variables needed from the other observations should be specified for +#' this parameter. The specified variables are added to the joined dataset +#' with suffix ".join". For example to select all observations with `AVALC == +#' "Y"` and `AVALC == "Y"` for at least one subsequent visit `join_vars = +#' exprs(AVALC, AVISITN)` and `condition = AVALC == "Y" & AVALC.join == "Y" & +#' AVISITN < AVISITN.join` could be specified. +#' +#' The `*.join` variables are not included in the output dataset. +#' +#' *Permitted Values*: a named list of expressions, e.g., created by `exprs()` +#' +#' @param join_type Observations to keep after joining +#' +#' The argument determines which of the joined observations are kept with +#' respect to the original observation. For example, if `join_type = +#' "after"` is specified all observations after the original observations are +#' kept. +#' +#' *Permitted Values:* `"before"`, `"after"`, `"all"` +#' +#' @param first_cond Condition for selecting range of data +#' +#' `r lifecycle::badge("deprecated")` +#' +#' This argument is *deprecated*, please use `first_cond_upper` instead. +#' +#' If this argument is specified, the other observations are restricted up to +#' the first observation where the specified condition is fulfilled. If the +#' condition is not fulfilled for any of the subsequent observations, all +#' observations are removed. +#' +#' *Permitted Values*: an unquoted condition +#' +#' @param first_cond_lower Condition for selecting range of data (before) +#' +#' If this argument is specified, the other observations are restricted from +#' the first observation before the current observation where the specified +#' condition is fulfilled up to the current observation. If the condition is +#' not fulfilled for any of the other observations, no observations are +#' considered, i.e., the observation is not flagged. +#' +#' This parameter should be specified if `condition` contains summary +#' functions which should not apply to all observations but only from a +#' certain observation before the current observation up to the current +#' observation. +#' +#' *Permitted Values*: an unquoted condition +#' +#' @param first_cond_upper Condition for selecting range of data (after) +#' +#' If this argument is specified, the other observations are restricted up to +#' the first observation where the specified condition is fulfilled. If the +#' condition is not fulfilled for any of the other observations, no +#' observations are considered, i.e., the observation is not flagged. +#' +#' This parameter should be specified if `condition` contains summary +#' functions which should not apply to all observations but only up to the +#' confirmation assessment. +#' +#' *Permitted Values*: an unquoted condition +#' +#' @param order If specified, the specified variables or expressions are used to +#' select the first observation. +#' +#' *Permitted Values*: list of expressions created by `exprs()`, e.g., +#' `exprs(ADT, desc(AVAL))` or `NULL` +#' +#' @inheritParams event +#' +#' @return An object of class `event_joined` +#' +#' @keywords source_specifications +#' @family source_specifications +#' +#' @seealso [derive_extreme_event()], [derive_vars_extreme_event()], [event()] +#' +#' @export +#' +#' @examples +#' library(tibble) +#' library(dplyr) +#' library(lubridate) +#' # Derive confirmed best overall response (using event_joined()) +#' # CR - complete response, PR - partial response, SD - stable disease +#' # NE - not evaluable, PD - progressive disease +#' adsl <- tribble( +#' ~USUBJID, ~TRTSDTC, +#' "1", "2020-01-01", +#' "2", "2019-12-12", +#' "3", "2019-11-11", +#' "4", "2019-12-30", +#' "5", "2020-01-01", +#' "6", "2020-02-02", +#' "7", "2020-02-02", +#' "8", "2020-02-01" +#' ) %>% +#' mutate(TRTSDT = ymd(TRTSDTC)) +#' +#' adrs <- tribble( +#' ~USUBJID, ~ADTC, ~AVALC, +#' "1", "2020-01-01", "PR", +#' "1", "2020-02-01", "CR", +#' "1", "2020-02-16", "NE", +#' "1", "2020-03-01", "CR", +#' "1", "2020-04-01", "SD", +#' "2", "2020-01-01", "SD", +#' "2", "2020-02-01", "PR", +#' "2", "2020-03-01", "SD", +#' "2", "2020-03-13", "CR", +#' "4", "2020-01-01", "PR", +#' "4", "2020-03-01", "NE", +#' "4", "2020-04-01", "NE", +#' "4", "2020-05-01", "PR", +#' "5", "2020-01-01", "PR", +#' "5", "2020-01-10", "PR", +#' "5", "2020-01-20", "PR", +#' "6", "2020-02-06", "PR", +#' "6", "2020-02-16", "CR", +#' "6", "2020-03-30", "PR", +#' "7", "2020-02-06", "PR", +#' "7", "2020-02-16", "CR", +#' "7", "2020-04-01", "NE", +#' "8", "2020-02-16", "PD" +#' ) %>% +#' mutate( +#' ADT = ymd(ADTC), +#' PARAMCD = "OVR", +#' PARAM = "Overall Response by Investigator" +#' ) %>% +#' derive_vars_merged( +#' dataset_add = adsl, +#' by_vars = exprs(USUBJID), +#' new_vars = exprs(TRTSDT) +#' ) +#' +#' derive_extreme_event( +#' adrs, +#' by_vars = exprs(USUBJID), +#' order = exprs(ADT), +#' mode = "first", +#' source_datasets = list(adsl = adsl), +#' events = list( +#' event_joined( +#' description = paste( +#' "CR needs to be confirmed by a second CR at least 28 days later", +#' "at most one NE is acceptable between the two assessments" +#' ), +#' join_vars = exprs(AVALC, ADT), +#' join_type = "after", +#' first_cond_upper = AVALC.join == "CR" & +#' ADT.join >= ADT + 28, +#' condition = AVALC == "CR" & +#' all(AVALC.join %in% c("CR", "NE")) & +#' count_vals(var = AVALC.join, val = "NE") <= 1, +#' set_values_to = exprs( +#' AVALC = "CR" +#' ) +#' ), +#' event_joined( +#' description = paste( +#' "PR needs to be confirmed by a second CR or PR at least 28 days later,", +#' "at most one NE is acceptable between the two assessments" +#' ), +#' join_vars = exprs(AVALC, ADT), +#' join_type = "after", +#' first_cond_upper = AVALC.join %in% c("CR", "PR") & +#' ADT.join >= ADT + 28, +#' condition = AVALC == "PR" & +#' all(AVALC.join %in% c("CR", "PR", "NE")) & +#' count_vals(var = AVALC.join, val = "NE") <= 1, +#' set_values_to = exprs( +#' AVALC = "PR" +#' ) +#' ), +#' event( +#' description = paste( +#' "CR, PR, or SD are considered as SD if occurring at least 28", +#' "after treatment start" +#' ), +#' condition = AVALC %in% c("CR", "PR", "SD") & ADT >= TRTSDT + 28, +#' set_values_to = exprs( +#' AVALC = "SD" +#' ) +#' ), +#' event( +#' condition = AVALC == "PD", +#' set_values_to = exprs( +#' AVALC = "PD" +#' ) +#' ), +#' event( +#' condition = AVALC %in% c("CR", "PR", "SD", "NE"), +#' set_values_to = exprs( +#' AVALC = "NE" +#' ) +#' ), +#' event( +#' description = "set response to MISSING for patients without records in ADRS", +#' dataset_name = "adsl", +#' condition = TRUE, +#' set_values_to = exprs( +#' AVALC = "MISSING" +#' ), +#' keep_source_vars = exprs(TRTSDT) +#' ) +#' ), +#' set_values_to = exprs( +#' PARAMCD = "CBOR", +#' PARAM = "Best Confirmed Overall Response by Investigator" +#' ) +#' ) %>% +#' filter(PARAMCD == "CBOR") +event_joined <- function(dataset_name = NULL, + condition, + order = NULL, + join_vars, + join_type, + first_cond = NULL, + first_cond_lower = NULL, + first_cond_upper = NULL, + set_values_to = NULL, + keep_source_vars = NULL, + description = NULL) { + if (!missing(first_cond)) { + deprecate_warn( + "1.0.0", + "event_joined(first_cond=)", + "event_joined(first_cond_upper=)" + ) + first_cond_upper <- assert_filter_cond(enexpr(first_cond), optional = TRUE) + } else { + first_cond_upper <- assert_filter_cond(enexpr(first_cond_upper), optional = TRUE) + } + + out <- list( + description = assert_character_scalar(description, optional = TRUE), + dataset_name = assert_character_scalar(dataset_name, optional = TRUE), + condition = assert_filter_cond(enexpr(condition), optional = TRUE), + order = assert_expr_list(order, optional = TRUE), + join_vars = assert_vars(join_vars), + join_type = assert_character_scalar( + join_type, + values = c("before", "after", "all"), + case_sensitive = FALSE + ), + first_cond_lower = assert_filter_cond(enexpr(first_cond_lower), optional = TRUE), + first_cond_upper = first_cond_upper, + set_values_to = assert_expr_list( + set_values_to, + named = TRUE, + optional = TRUE + ), + keep_source_vars = assert_expr_list(keep_source_vars, optional = TRUE) + ) + class(out) <- c("event_joined", "event_def", "source", "list") + out +} diff --git a/inst/templates/ad_adsl.R b/inst/templates/ad_adsl.R index a2b480f5d6..820a603a91 100644 --- a/inst/templates/ad_adsl.R +++ b/inst/templates/ad_adsl.R @@ -194,29 +194,49 @@ adsl <- adsl %>% ## Last known alive date ---- ## DTC variables are converted to numeric dates imputing missing day and month ## to the first -ae_start_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AESTDTC, highest_imputation = "M") -) -ae_end_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AEENDTC, highest_imputation = "M") -) -lb_date <- date_source( - dataset_name = "lb", - date = convert_dtc_to_dt(LBDTC, highest_imputation = "M") -) -trt_end_date <- date_source( - dataset_name = "adsl", - date = TRTEDT -) adsl <- adsl %>% - derive_var_extreme_dt( - new_var = LSTALVDT, - ae_start_date, ae_end_date, lb_date, trt_end_date, + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + order = exprs(AESTDTC, AESEQ), + condition = !is.na(AESTDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AESTDTC, highest_imputation = "M"), + seq = AESEQ + ), + ), + event( + dataset_name = "ae", + order = exprs(AEENDTC, AESEQ), + condition = !is.na(AEENDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AEENDTC, highest_imputation = "M"), + seq = AESEQ + ), + ), + event( + dataset_name = "lb", + order = exprs(LBDTC, LBSEQ), + condition = !is.na(LBDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(LBDTC, highest_imputation = "M"), + seq = LBSEQ + ), + ), + event( + dataset_name = "adsl", + condition = !is.na(TRTEDT), + set_values_to = exprs(LSTALVDT = TRTEDT, seq = NA_integer_), + ) + ), source_datasets = list(ae = ae, lb = lb, adsl = adsl), - mode = "last" + tmp_event_nr_var = event_nr, + order = exprs(LSTALVDT, seq, event_nr), + mode = "last", + new_vars = exprs(LSTALVDT) ) %>% derive_var_merged_exist_flag( dataset_add = ex, diff --git a/man/basket_select.Rd b/man/basket_select.Rd index 43c743b0b5..97f260b9c4 100644 --- a/man/basket_select.Rd +++ b/man/basket_select.Rd @@ -36,9 +36,7 @@ Exactly one of \code{name} or \code{id} must be specified. Source Objects: \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/censor_source.Rd b/man/censor_source.Rd index 8b426db250..cea32fcd4b 100644 --- a/man/censor_source.Rd +++ b/man/censor_source.Rd @@ -64,9 +64,7 @@ censor_source( Source Objects: \code{\link{basket_select}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/date_source.Rd b/man/date_source.Rd index 7b3cc6d1c3..5747dd6b19 100644 --- a/man/date_source.Rd +++ b/man/date_source.Rd @@ -33,6 +33,9 @@ an expression, or \code{NA}. An object of class \code{date_source}. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{date_source()} +function has been superseded in favor of \code{derive_vars_extreme_event()}. + Create a \code{date_source} object as input for \code{derive_var_extreme_dt()} and \code{derive_var_extreme_dtm()}. } @@ -64,18 +67,13 @@ death_date <- date_source( \seealso{ \code{\link[=derive_var_extreme_dtm]{derive_var_extreme_dtm()}}, \code{\link[=derive_var_extreme_dt]{derive_var_extreme_dt()}} -Source Objects: -\code{\link{basket_select}()}, -\code{\link{censor_source}()}, -\code{\link{death_event}}, +Other superseded: +\code{\link{derive_param_extreme_record}()}, +\code{\link{derive_var_dthcaus}()}, +\code{\link{derive_var_extreme_dtm}()}, +\code{\link{derive_var_extreme_dt}()}, \code{\link{dthcaus_source}()}, -\code{\link{event_joined}()}, -\code{\link{event_source}()}, -\code{\link{event}()}, -\code{\link{flag_event}()}, -\code{\link{query}()}, -\code{\link{records_source}()}, -\code{\link{tte_source}()} +\code{\link{get_summary_records}()} } -\concept{source_specifications} -\keyword{source_specifications} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_extreme_event.Rd b/man/derive_extreme_event.Rd index 6027af051e..05377ae6a0 100644 --- a/man/derive_extreme_event.Rd +++ b/man/derive_extreme_event.Rd @@ -5,16 +5,16 @@ \title{Add the Worst or Best Observation for Each By Group as New Records} \usage{ derive_extreme_event( - dataset, + dataset = NULL, by_vars = NULL, events, tmp_event_nr_var = NULL, order, mode, source_datasets = NULL, - ignore_event_order = FALSE, + ignore_event_order = NULL, check_type = "warning", - set_values_to, + set_values_to = NULL, keep_source_vars = exprs(everything()) ) } @@ -38,7 +38,7 @@ record sorted by \code{order}. The data is grouped by \code{by_vars}, i.e., summ functions like \code{all()} or \code{any()} can be used in \code{condition}. For \code{event_joined()} events the observations are selected by calling -\code{filter_joined}. The \code{condition} field is passed to the \code{filter} argument.} +\code{filter_joined()}. The \code{condition} field is passed to the \code{filter_join} argument.} \item{tmp_event_nr_var}{Temporary event number variable @@ -394,7 +394,7 @@ derive_extreme_event( } \seealso{ -\code{\link[=event]{event()}}, \code{\link[=event_joined]{event_joined()}} +\code{\link[=event]{event()}}, \code{\link[=event_joined]{event_joined()}}, \code{\link[=derive_vars_extreme_event]{derive_vars_extreme_event()}} BDS-Findings Functions for adding Parameters/Records: \code{\link{default_qtc_paramcd}()}, diff --git a/man/derive_param_extreme_record.Rd b/man/derive_param_extreme_record.Rd index 35739e25cf..fbd59c0669 100644 --- a/man/derive_param_extreme_record.Rd +++ b/man/derive_param_extreme_record.Rd @@ -143,6 +143,11 @@ derive_param_extreme_record( } \seealso{ Other superseded: +\code{\link{date_source}()}, +\code{\link{derive_var_dthcaus}()}, +\code{\link{derive_var_extreme_dtm}()}, +\code{\link{derive_var_extreme_dt}()}, +\code{\link{dthcaus_source}()}, \code{\link{get_summary_records}()} } \concept{superseded} diff --git a/man/derive_var_age_years.Rd b/man/derive_var_age_years.Rd index 41ac270f03..3bf6c18287 100644 --- a/man/derive_var_age_years.Rd +++ b/man/derive_var_age_years.Rd @@ -72,10 +72,8 @@ derive_var_age_years(data, AGE, age_unit = "months", new_var = AAGE) \code{\link[=derive_vars_duration]{derive_vars_duration()}} ADSL Functions that returns variable appended to dataset: -\code{\link{derive_var_dthcaus}()}, -\code{\link{derive_var_extreme_dtm}()}, -\code{\link{derive_var_extreme_dt}()}, \code{\link{derive_vars_aage}()}, +\code{\link{derive_vars_extreme_event}()}, \code{\link{derive_vars_period}()} } \concept{der_adsl} diff --git a/man/derive_var_dthcaus.Rd b/man/derive_var_dthcaus.Rd index 3bf7d2c0a6..5cf2117bd3 100644 --- a/man/derive_var_dthcaus.Rd +++ b/man/derive_var_dthcaus.Rd @@ -30,6 +30,9 @@ A list of expressions where the expressions are symbols as returned by The input dataset with \code{DTHCAUS} variable added. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_var_dthcaus()} +function has been superseded in favor of \code{derive_vars_extreme_event()}. + Derive death cause (\code{DTHCAUS}) and add traceability variables if required. } \details{ @@ -144,12 +147,13 @@ derive_var_dthcaus( \seealso{ \code{\link[=dthcaus_source]{dthcaus_source()}} -ADSL Functions that returns variable appended to dataset: -\code{\link{derive_var_age_years}()}, +Other superseded: +\code{\link{date_source}()}, +\code{\link{derive_param_extreme_record}()}, \code{\link{derive_var_extreme_dtm}()}, \code{\link{derive_var_extreme_dt}()}, -\code{\link{derive_vars_aage}()}, -\code{\link{derive_vars_period}()} +\code{\link{dthcaus_source}()}, +\code{\link{get_summary_records}()} } -\concept{der_adsl} -\keyword{der_adsl} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_var_extreme_dt.Rd b/man/derive_var_extreme_dt.Rd index f8ca9d3d50..f1bcc89963 100644 --- a/man/derive_var_extreme_dt.Rd +++ b/man/derive_var_extreme_dt.Rd @@ -42,6 +42,9 @@ A list of expressions where the expressions are symbols as returned by The input dataset with the new variable added. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_var_extreme_dt()} +function has been superseded in favor of \code{derive_vars_extreme_event()}. + Add the first or last date from multiple sources to the dataset, e.g., the last known alive date (\code{LSTALVDT}). @@ -236,12 +239,13 @@ dm \%>\% \seealso{ \code{\link[=date_source]{date_source()}}, \code{\link[=derive_var_extreme_dtm]{derive_var_extreme_dtm()}}, \code{\link[=derive_vars_merged]{derive_vars_merged()}} -ADSL Functions that returns variable appended to dataset: -\code{\link{derive_var_age_years}()}, +Other superseded: +\code{\link{date_source}()}, +\code{\link{derive_param_extreme_record}()}, \code{\link{derive_var_dthcaus}()}, \code{\link{derive_var_extreme_dtm}()}, -\code{\link{derive_vars_aage}()}, -\code{\link{derive_vars_period}()} +\code{\link{dthcaus_source}()}, +\code{\link{get_summary_records}()} } -\concept{der_adsl} -\keyword{der_adsl} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_var_extreme_dtm.Rd b/man/derive_var_extreme_dtm.Rd index f63a698887..a07864e852 100644 --- a/man/derive_var_extreme_dtm.Rd +++ b/man/derive_var_extreme_dtm.Rd @@ -42,6 +42,9 @@ A list of expressions where the expressions are symbols as returned by The input dataset with the new variable added. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_var_extreme_dtm()} +function has been superseded in favor of \code{derive_vars_extreme_event()}. + Add the first or last datetime from multiple sources to the dataset, e.g., the last known alive datetime (\code{LSTALVDTM}). } @@ -235,12 +238,13 @@ dm \%>\% \code{\link[=date_source]{date_source()}}, \code{\link[=derive_var_extreme_dt]{derive_var_extreme_dt()}}, \code{\link[=derive_vars_merged]{derive_vars_merged()}} -ADSL Functions that returns variable appended to dataset: -\code{\link{derive_var_age_years}()}, +Other superseded: +\code{\link{date_source}()}, +\code{\link{derive_param_extreme_record}()}, \code{\link{derive_var_dthcaus}()}, \code{\link{derive_var_extreme_dt}()}, -\code{\link{derive_vars_aage}()}, -\code{\link{derive_vars_period}()} +\code{\link{dthcaus_source}()}, +\code{\link{get_summary_records}()} } -\concept{der_adsl} -\keyword{der_adsl} +\concept{superseded} +\keyword{superseded} diff --git a/man/derive_vars_aage.Rd b/man/derive_vars_aage.Rd index 6f1bc32566..d731aa1a16 100644 --- a/man/derive_vars_aage.Rd +++ b/man/derive_vars_aage.Rd @@ -100,9 +100,7 @@ derive_vars_aage(data) ADSL Functions that returns variable appended to dataset: \code{\link{derive_var_age_years}()}, -\code{\link{derive_var_dthcaus}()}, -\code{\link{derive_var_extreme_dtm}()}, -\code{\link{derive_var_extreme_dt}()}, +\code{\link{derive_vars_extreme_event}()}, \code{\link{derive_vars_period}()} } \concept{der_adsl} diff --git a/man/derive_vars_extreme_event.Rd b/man/derive_vars_extreme_event.Rd new file mode 100644 index 0000000000..da5ba26ce4 --- /dev/null +++ b/man/derive_vars_extreme_event.Rd @@ -0,0 +1,237 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/derive_vars_extreme_event.R +\name{derive_vars_extreme_event} +\alias{derive_vars_extreme_event} +\title{Add the Worst or Best Observation for Each By Group as New Variables} +\usage{ +derive_vars_extreme_event( + dataset, + by_vars = NULL, + events, + tmp_event_nr_var = NULL, + order, + mode, + source_datasets = NULL, + check_type = "warning", + new_vars +) +} +\arguments{ +\item{dataset}{Input dataset + +The variables specified by the \code{by_vars} and \code{order} arguments are expected to be in the dataset.} + +\item{by_vars}{Grouping variables + +\emph{Default}: \code{NULL} + +\emph{Permitted Values:} list of variables created by \code{exprs()}} + +\item{events}{Conditions and new values defining events + +A list of \code{event()} or \code{event_joined()} objects is expected. Only +observations listed in the \code{events} are considered for deriving extreme +event. If multiple records meet the filter \code{condition}, take the first +record sorted by \code{order}. The data is grouped by \code{by_vars}, i.e., summary +functions like \code{all()} or \code{any()} can be used in \code{condition}. + +For \code{event_joined()} events the observations are selected by calling +\code{filter_joined()}. The \code{condition} field is passed to the \code{filter_join} argument.} + +\item{tmp_event_nr_var}{Temporary event number variable + +The specified variable is added to all source datasets and is set to the +number of the event before selecting the records of the event. + +It can be used in \code{order} to determine which record should be used if +records from more than one event are selected. + +The variable is not included in the output dataset.} + +\item{order}{Sort order + +If a particular event from \code{events} has more than one observation, within +the event and by group, the records are ordered by the specified order. + +\emph{Permitted Values:} list of expressions created by \code{exprs()}, e.g., +\code{exprs(ADT, desc(AVAL))}} + +\item{mode}{Selection mode (first or last) + +If a particular event from \code{events} has more than one observation, +\code{"first"}/\code{"last"} is used to select the first/last record of this type of +event sorting by \code{order}. + +\emph{Permitted Values:} \code{"first"}, \code{"last"}} + +\item{source_datasets}{Source datasets + +A named list of datasets is expected. The \code{dataset_name} field of \code{event()} +and \code{event_joined()} refers to the dataset provided in the list.} + +\item{check_type}{Check uniqueness? + +If \code{"warning"} or \code{"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. + +\emph{Default:} \code{"warning"} + +\emph{Permitted Values:} \code{"none"}, \code{"warning"}, \code{"error"}} + +\item{new_vars}{Variables to add + +The specified variables from the events are added to the output +dataset. Variables can be renamed by naming the element, i.e., \verb{new_vars = exprs( = )}.} +} +\value{ +The input dataset with the best or worst observation of each by group +added as new variables. +} +\description{ +Add the first available record from \code{events} for each by group as new +variables, all variables of the selected observation are kept. It can be used +for selecting the extreme observation from a series of user-defined events. +} +\details{ +\enumerate{ +\item For each event select the observations to consider: +\enumerate{ +\item If the event is of class \code{event}, the observations of the source dataset +are restricted by \code{condition} and then the first or last (\code{mode}) +observation per by group (\code{by_vars}) is selected. + +If the event is of class \code{event_joined}, \code{filter_joined()} is called to +select the observations. +\item The variables specified by the \code{set_values_to} field of the event +are added to the selected observations. +\item The variable specified for \code{tmp_event_nr_var} is added and set to +the number of the event. +} +\item All selected observations are bound together. +\item For each group (with respect to the variables specified for the +\code{by_vars} parameter) the first or last observation (with respect to the +order specified for the \code{order} parameter and the mode specified for the +\code{mode} parameter) is selected. +\item The variables specified by the \code{new_vars} parameter are added to +the selected observations. +\item The variables are added to input dataset. +} +} +\examples{ +library(tibble) +library(dplyr) +library(lubridate) + +adsl <- tribble( + ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, + "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), + "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), + "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), + "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), + "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), +) + +lb <- tribble( + ~STUDYID, ~DOMAIN, ~USUBJID, ~LBSEQ, ~LBDTC, + "PILOT01", "LB", "01-1130", 219, "2014-06-07T13:20", + "PILOT01", "LB", "01-1130", 322, "2014-08-16T13:10", + "PILOT01", "LB", "01-1133", 268, "2013-04-18T15:30", + "PILOT01", "LB", "01-1133", 304, "2013-05-01T10:13", + "PILOT01", "LB", "01-1211", 8, "2012-10-30T14:26", + "PILOT01", "LB", "01-1211", 162, "2013-01-08T12:13", + "PILOT01", "LB", "09-1081", 47, "2014-02-01T10:55", + "PILOT01", "LB", "09-1081", 219, "2014-05-10T11:15", + "PILOT01", "LB", "09-1088", 283, "2014-09-27T12:13", + "PILOT01", "LB", "09-1088", 322, "2014-10-09T13:25" +) \%>\% + mutate( + ADT = convert_dtc_to_dt(LBDTC) + ) + +derive_vars_extreme_event( + adsl, + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "adsl", + condition = !is.na(DTHDT), + set_values_to = exprs(LSTALVDT = DTHDT, DTHFL = "Y") + ), + event( + dataset_name = "lb", + condition = !is.na(ADT), + order = exprs(ADT), + mode = "last", + set_values_to = exprs(LSTALVDT = ADT, DTHFL = "N") + ), + event( + dataset_name = "adsl", + condition = !is.na(TRTEDT), + order = exprs(TRTEDT), + mode = "last", + set_values_to = exprs(LSTALVDT = TRTEDT, DTHFL = "N") + ) + ), + source_datasets = list(adsl = adsl, lb = lb), + tmp_event_nr_var = event_nr, + order = exprs(LSTALVDT, event_nr), + mode = "last", + new_vars = exprs(LSTALVDT, DTHFL) +) + +# Derive DTHCAUS from AE and DS domain data +adsl <- tribble( + ~STUDYID, ~USUBJID, + "STUDY01", "PAT01", + "STUDY01", "PAT02", + "STUDY01", "PAT03" +) +ae <- tribble( + ~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC, + "STUDY01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-04", + "STUDY01", "PAT01", 13, "CARDIAC ARREST", "FATAL", "2021-04-03", +) + +ds <- tribble( + ~STUDYID, ~USUBJID, ~DSSEQ, ~DSDECOD, ~DSTERM, ~DSSTDTC, + "STUDY01", "PAT02", 1, "INFORMED CONSENT OBTAINED", "INFORMED CONSENT OBTAINED", "2021-04-03", + "STUDY01", "PAT02", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11", + "STUDY01", "PAT02", 3, "DEATH", "DEATH DUE TO PROGRESSION OF DISEASE", "2022-02-01", + "STUDY01", "PAT03", 1, "DEATH", "POST STUDY REPORTING OF DEATH", "2022-03-03" +) + +derive_vars_extreme_event( + adsl, + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + condition = AEOUT == "FATAL", + set_values_to = exprs(DTHCAUS = AEDECOD, DTHDT = convert_dtc_to_dt(AEDTHDTC)), + order = exprs(DTHDT) + ), + event( + dataset_name = "ds", + condition = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), + set_values_to = exprs(DTHCAUS = DSTERM, DTHDT = convert_dtc_to_dt(DSSTDTC)), + order = exprs(DTHDT) + ) + ), + source_datasets = list(ae = ae, ds = ds), + tmp_event_nr_var = event_nr, + order = exprs(DTHDT, event_nr), + mode = "first", + new_vars = exprs(DTHCAUS, DTHDT) +) +} +\seealso{ +\code{\link[=event]{event()}}, \code{\link[=event_joined]{event_joined()}}, \code{\link[=derive_extreme_event]{derive_extreme_event()}} + +ADSL Functions that returns variable appended to dataset: +\code{\link{derive_var_age_years}()}, +\code{\link{derive_vars_aage}()}, +\code{\link{derive_vars_period}()} +} +\concept{der_adsl} +\keyword{der_adsl} diff --git a/man/derive_vars_period.Rd b/man/derive_vars_period.Rd index 78a01d8f9e..d5297e7774 100644 --- a/man/derive_vars_period.Rd +++ b/man/derive_vars_period.Rd @@ -138,10 +138,8 @@ derive_vars_period( ADSL Functions that returns variable appended to dataset: \code{\link{derive_var_age_years}()}, -\code{\link{derive_var_dthcaus}()}, -\code{\link{derive_var_extreme_dtm}()}, -\code{\link{derive_var_extreme_dt}()}, -\code{\link{derive_vars_aage}()} +\code{\link{derive_vars_aage}()}, +\code{\link{derive_vars_extreme_event}()} } \concept{der_adsl} \keyword{der_adsl} diff --git a/man/dthcaus_source.Rd b/man/dthcaus_source.Rd index 6e99d293eb..93f118b4ac 100644 --- a/man/dthcaus_source.Rd +++ b/man/dthcaus_source.Rd @@ -60,7 +60,9 @@ expressions referring to existing variables. An object of class "dthcaus_source". } \description{ -Create a \code{dthcaus_source} Object +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} The \code{derive_var_dthcaus()} +function and \code{dthcaus_source()} have been superseded in favor of +\code{derive_vars_extreme_event()}. } \examples{ # Deaths sourced from AE @@ -84,18 +86,13 @@ src_ds <- dthcaus_source( \seealso{ \code{\link[=derive_var_dthcaus]{derive_var_dthcaus()}} -Source Objects: -\code{\link{basket_select}()}, -\code{\link{censor_source}()}, +Other superseded: \code{\link{date_source}()}, -\code{\link{death_event}}, -\code{\link{event_joined}()}, -\code{\link{event_source}()}, -\code{\link{event}()}, -\code{\link{flag_event}()}, -\code{\link{query}()}, -\code{\link{records_source}()}, -\code{\link{tte_source}()} +\code{\link{derive_param_extreme_record}()}, +\code{\link{derive_var_dthcaus}()}, +\code{\link{derive_var_extreme_dtm}()}, +\code{\link{derive_var_extreme_dt}()}, +\code{\link{get_summary_records}()} } -\concept{source_specifications} -\keyword{source_specifications} +\concept{superseded} +\keyword{superseded} diff --git a/man/event.Rd b/man/event.Rd index 1cc360122c..22541cae91 100644 --- a/man/event.Rd +++ b/man/event.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_extreme_event.R +% Please edit documentation in R/event.R \name{event} \alias{event} \title{Create a \code{event} Object} @@ -66,17 +66,15 @@ An object of class \code{event} } \description{ The \code{event} object is used to define events as input for the -\code{derive_extreme_event()} function. +\code{derive_extreme_event()} and \code{derive_vars_extreme_event()} functions. } \seealso{ -\code{\link[=derive_extreme_event]{derive_extreme_event()}}, \code{\link[=event_joined]{event_joined()}} +\code{\link[=derive_extreme_event]{derive_extreme_event()}}, \code{\link[=derive_vars_extreme_event]{derive_vars_extreme_event()}}, \code{\link[=event_joined]{event_joined()}} Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{flag_event}()}, diff --git a/man/event_joined.Rd b/man/event_joined.Rd index dd64f3c866..2d445d2407 100644 --- a/man/event_joined.Rd +++ b/man/event_joined.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/derive_extreme_event.R +% Please edit documentation in R/event.R \name{event_joined} \alias{event_joined} \title{Create a \code{event_joined} Object} @@ -132,10 +132,11 @@ An object of class \code{event_joined} } \description{ The \code{event_joined} object is used to define events as input for the -\code{derive_extreme_event()} function. This object should be used if the event -does not depend on a single observation of the source dataset but on multiple -observations. For example, if the event needs to be confirmed by a second -observation of the source dataset. +\code{derive_extreme_event()} and \code{derive_vars_extreme_event()} functions. +This object should be used if the event does not depend on a single +observation of the source dataset but on multiple observations. For example, +if the event needs to be confirmed by a second observation of the source +dataset. The events are selected by calling \code{filter_joined()}. See its documentation for more details. @@ -276,14 +277,12 @@ derive_extreme_event( filter(PARAMCD == "CBOR") } \seealso{ -\code{\link[=derive_extreme_event]{derive_extreme_event()}}, \code{\link[=event]{event()}} +\code{\link[=derive_extreme_event]{derive_extreme_event()}}, \code{\link[=derive_vars_extreme_event]{derive_vars_extreme_event()}}, \code{\link[=event]{event()}} Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_source}()}, \code{\link{event}()}, \code{\link{flag_event}()}, diff --git a/man/event_source.Rd b/man/event_source.Rd index dca5cc91e9..75b3321c1d 100644 --- a/man/event_source.Rd +++ b/man/event_source.Rd @@ -55,9 +55,7 @@ event_source( Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event}()}, \code{\link{flag_event}()}, diff --git a/man/flag_event.Rd b/man/flag_event.Rd index 338fd0660d..4790cdd3e5 100644 --- a/man/flag_event.Rd +++ b/man/flag_event.Rd @@ -38,9 +38,7 @@ The \code{flag_event} object is used to define events as input for the Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/get_summary_records.Rd b/man/get_summary_records.Rd index 498b4f1c40..1c0b9c610e 100644 --- a/man/get_summary_records.Rd +++ b/man/get_summary_records.Rd @@ -170,7 +170,12 @@ get_summary_records( \code{\link[=derive_summary_records]{derive_summary_records()}}, \code{\link[=derive_var_merged_summary]{derive_var_merged_summary()}} Other superseded: -\code{\link{derive_param_extreme_record}()} +\code{\link{date_source}()}, +\code{\link{derive_param_extreme_record}()}, +\code{\link{derive_var_dthcaus}()}, +\code{\link{derive_var_extreme_dtm}()}, +\code{\link{derive_var_extreme_dt}()}, +\code{\link{dthcaus_source}()} } \concept{superseded} \keyword{superseded} diff --git a/man/query.Rd b/man/query.Rd index 4bcc0aefb3..df454b1996 100644 --- a/man/query.Rd +++ b/man/query.Rd @@ -137,9 +137,7 @@ query( Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/records_source.Rd b/man/records_source.Rd index 5fb5ce54c3..2b47fab421 100644 --- a/man/records_source.Rd +++ b/man/records_source.Rd @@ -43,9 +43,7 @@ The \code{records_source} object is used to find extreme records of interest. Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/tte_source.Rd b/man/tte_source.Rd index 4b5518078f..612ef672de 100644 --- a/man/tte_source.Rd +++ b/man/tte_source.Rd @@ -43,9 +43,7 @@ The \code{tte_source} object is used to define events and possible censorings. Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, \code{\link{death_event}}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/man/tte_source_objects.Rd b/man/tte_source_objects.Rd index 768c7647a6..2668d39355 100644 --- a/man/tte_source_objects.Rd +++ b/man/tte_source_objects.Rd @@ -63,8 +63,6 @@ for (obj in list_tte_source_objects()$object) { Source Objects: \code{\link{basket_select}()}, \code{\link{censor_source}()}, -\code{\link{date_source}()}, -\code{\link{dthcaus_source}()}, \code{\link{event_joined}()}, \code{\link{event_source}()}, \code{\link{event}()}, diff --git a/tests/testthat/test-derive_extreme_event.R b/tests/testthat/test-derive_extreme_event.R index 58b6e896b5..a2f336d65b 100644 --- a/tests/testthat/test-derive_extreme_event.R +++ b/tests/testthat/test-derive_extreme_event.R @@ -341,6 +341,7 @@ test_that("derive_extreme_event Test 4: event-specific mode", { ) }) + ## Test 5: event_joined() is handled correctly ---- test_that("derive_extreme_event Test 5: event_joined() is handled correctly", { adsl <- tibble::tribble( @@ -621,40 +622,56 @@ test_that("derive_extreme_event Test 7: deprecation of ignore_event_order", { ) }) -# event_joined ---- -## Test 8: deprecation of `first_cond` ---- -test_that("event_joined Test 8: deprecation of `first_cond`", { - new_event <- event_joined( - join_vars = exprs(AVALC, ADT), - join_type = "after", - first_cond_upper = AVALC.join == "CR" & - ADT.join >= ADT + 28, - condition = AVALC == "CR" & - all(AVALC.join %in% c("CR", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= 1, - set_values_to = exprs( - AVALC = "CR" - ) - ) +## Test 8: deprecation of ignore_event_order ---- +test_that("derive_extreme_event Test 8: deprecation of ignore_event_order", { + adrs <- tibble::tribble( + ~USUBJID, ~AVISITN, ~AVALC, + "1", 1, "PR", + "1", 2, "CR", + "1", 3, "CR" + ) %>% + mutate(PARAMCD = "OVR") expect_warning( - old_event <- event_joined( - join_vars = exprs(AVALC, ADT), - join_type = "after", - first_cond = AVALC.join == "CR" & - ADT.join >= ADT + 28, - condition = AVALC == "CR" & - all(AVALC.join %in% c("CR", "NE")) & - count_vals(var = AVALC.join, val = "NE") <= 1, + actual <- derive_extreme_event( + adrs, + by_vars = exprs(USUBJID), + order = exprs(AVISITN), + mode = "first", + events = list( + event_joined( + join_vars = exprs(AVALC), + join_type = "after", + first_cond_upper = AVALC.join == "CR", + condition = AVALC == "CR", + set_values_to = exprs(AVALC = "Y") + ), + event_joined( + join_vars = exprs(AVALC), + join_type = "after", + first_cond_upper = AVALC.join %in% c("CR", "PR"), + condition = AVALC == "PR", + set_values_to = exprs(AVALC = "Y") + ) + ), + ignore_event_order = FALSE, set_values_to = exprs( - AVALC = "CR" + PARAMCD = "CRSP" ) ), class = "lifecycle_warning_deprecated" ) + expected <- bind_rows( + adrs, + tibble::tribble( + ~USUBJID, ~AVISITN, ~AVALC, ~PARAMCD, + "1", 1, "Y", "CRSP" + ) + ) - expect_equal( - old_event, - expected = new_event + expect_dfs_equal( + base = expected, + compare = actual, + keys = c("USUBJID", "PARAMCD", "AVISITN") ) }) diff --git a/tests/testthat/test-derive_vars_extreme_event.R b/tests/testthat/test-derive_vars_extreme_event.R new file mode 100644 index 0000000000..369ea283ce --- /dev/null +++ b/tests/testthat/test-derive_vars_extreme_event.R @@ -0,0 +1,47 @@ +## Test 1: derive_vars_extreme_event ---- +test_that("derive_vars_extreme_event Test 1: derive_vars_extreme_event", { + adsl <- tribble( + ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, + "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), + "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), + "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), + "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), + "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), + ) + + actual <- derive_vars_extreme_event( + adsl, + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "adsl", + condition = !is.na(DTHDT), + set_values_to = exprs(LSTALVDT = DTHDT, DTHFL = "Y") + ), + event( + dataset_name = "adsl", + condition = !is.na(TRTEDT), + set_values_to = exprs(LSTALVDT = TRTEDT, DTHFL = "N") + ) + ), + source_datasets = list(adsl = adsl), + order = exprs(LSTALVDT), + mode = "last", + new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) + ) + + expected <- tribble( + ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, ~LSTALVDT, ~DTHFL, + "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), ymd("2014-09-13"), "Y", + "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), ymd("2013-04-28"), "N", + "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), ymd("2013-01-12"), "N", + "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), ymd("2014-04-27"), "N", + "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), ymd("2014-11-01"), "Y", + ) + + expect_dfs_equal( + base = expected, + compare = actual, + keys = c("STUDYID", "USUBJID") + ) +}) diff --git a/tests/testthat/test-event.R b/tests/testthat/test-event.R new file mode 100644 index 0000000000..97a2b6d620 --- /dev/null +++ b/tests/testthat/test-event.R @@ -0,0 +1,113 @@ +## Test 1: Cover event$order ---- +test_that("event Test 1: Cover event$order", { + adsl_ext <- tribble( + ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, + "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), + "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), + "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), + "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), + "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), + ) + + lb_ext <- tribble( + ~STUDYID, ~DOMAIN, ~USUBJID, ~LBSEQ, ~LBDTC, + "PILOT01", "LB", "01-1130", 219, "2014-06-07T13:20", + "PILOT01", "LB", "01-1130", 322, "2014-08-16T13:10", + "PILOT01", "LB", "01-1133", 268, "2013-04-18T15:30", + "PILOT01", "LB", "01-1133", 304, "2013-05-01T10:13", + "PILOT01", "LB", "01-1211", 8, "2012-10-30T14:26", + "PILOT01", "LB", "01-1211", 162, "2013-01-08T12:13", + "PILOT01", "LB", "09-1081", 47, "2014-02-01T10:55", + "PILOT01", "LB", "09-1081", 219, "2014-05-10T11:15", + "PILOT01", "LB", "09-1088", 283, "2014-09-27T12:13", + "PILOT01", "LB", "09-1088", 322, "2014-10-09T13:25" + ) %>% + mutate( + ADT = convert_dtc_to_dt(LBDTC) + ) + + expected_output <- tribble( + ~STUDYID, ~USUBJID, ~TRTEDT, ~DTHDT, ~LSTALVDT, ~DTHFL, + "PILOT01", "01-1130", ymd("2014-08-16"), ymd("2014-09-13"), ymd("2014-09-13"), "Y", + "PILOT01", "01-1133", ymd("2013-04-28"), ymd(""), ymd("2013-05-01"), "N", + "PILOT01", "01-1211", ymd("2013-01-12"), ymd(""), ymd("2013-01-12"), "N", + "PILOT01", "09-1081", ymd("2014-04-27"), ymd(""), ymd("2014-05-10"), "N", + "PILOT01", "09-1088", ymd("2014-10-09"), ymd("2014-11-01"), ymd("2014-11-01"), "Y", + ) + + actual_output <- derive_vars_extreme_event( + adsl_ext, + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "adsl_ext", + condition = !is.na(DTHDT), + set_values_to = exprs(LSTALVDT = DTHDT, DTHFL = "Y") + ), + event( + dataset_name = "lb_ext", + condition = !is.na(ADT), + order = exprs(ADT, LBSEQ), + mode = "last", + set_values_to = exprs(LSTALVDT = ADT, DTHFL = "N") + ), + event( + dataset_name = "adsl_ext", + condition = !is.na(TRTEDT), + order = exprs(TRTEDT), + mode = "last", + set_values_to = exprs(LSTALVDT = TRTEDT, DTHFL = "N") + ) + ), + source_datasets = list(adsl_ext = adsl_ext, lb_ext = lb_ext), + tmp_event_nr_var = event_nr, + order = exprs(LSTALVDT, event_nr), + mode = "last", + new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) + ) + + + expect_dfs_equal( + base = expected_output, + compare = actual_output, + keys = c("USUBJID") + ) +}) + +# event_joined ---- +## Test 2: deprecation of `first_cond` ---- +test_that("event_joined Test 2: deprecation of `first_cond`", { + new_event <- event_joined( + join_vars = exprs(AVALC, ADT), + join_type = "after", + first_cond_upper = AVALC.join == "CR" & + ADT.join >= ADT + 28, + condition = AVALC == "CR" & + all(AVALC.join %in% c("CR", "NE")) & + count_vals(var = AVALC.join, val = "NE") <= 1, + set_values_to = exprs( + AVALC = "CR" + ) + ) + + expect_warning( + old_event <- event_joined( + join_vars = exprs(AVALC, ADT), + join_type = "after", + first_cond = AVALC.join == "CR" & + ADT.join >= ADT + 28, + condition = AVALC == "CR" & + all(AVALC.join %in% c("CR", "NE")) & + count_vals(var = AVALC.join, val = "NE") <= 1, + set_values_to = exprs( + AVALC = "CR" + ) + ), + class = "lifecycle_warning_deprecated" + ) + + expect_equal( + old_event, + expected = new_event + ) +}) diff --git a/vignettes/adsl.Rmd b/vignettes/adsl.Rmd index 577f9877ba..1345f38311 100644 --- a/vignettes/adsl.Rmd +++ b/vignettes/adsl.Rmd @@ -415,7 +415,7 @@ See also [Date and Time Imputation](imputation.html). ### Cause of Death (`DTHCAUS`) {#death_cause} -The cause of death `DTHCAUS` can be derived using the function `derive_var_dthcaus()`. +The cause of death `DTHCAUS` can be derived using the function `derive_vars_extreme_event()`. Since the cause of death could be collected/mapped in different domains (e.g. `DS`, `AE`, `DD`), it is important the user specifies the right source(s) to derive the cause of death from. @@ -423,64 +423,32 @@ is important the user specifies the right source(s) to derive the cause of death For example, if the date of death is collected in the AE form when the AE is Fatal, the cause of death would be set to the preferred term (`AEDECOD`) of that Fatal AE, while if the date of death is collected in the `DS` form, the cause of death would be set to the disposition term (`DSTERM`). -To achieve this, the `dthcaus_source()` objects must be specified and defined such as it fits the +To achieve this, the `event()` objects within `derive_vars_extreme_event()` must be specified and defined such that they fit the study requirement. -`dthcaus_source()` specifications: - -- `dataset_name`: the name of the dataset where to search for death information, -- `filter`: the condition to define death, -- `date`: the date of death, -- `mode`: `first` or `last` to select the first/last date of death if multiple dates are collected, -- `dthcaus`: variable or text used to populate `DTHCAUS`. -- `set_values_to`: whether the traceability variables need to be added (e.g source domain, -sequence, variable) - -An example call to define the sources would be: - -```{r eval=TRUE} -src_ae <- dthcaus_source( - dataset_name = "ae", - filter = AEOUT == "FATAL", - date = convert_dtc_to_dtm(AESTDTC, highest_imputation = "M"), - mode = "first", - dthcaus = AEDECOD -) -``` - -```{r, eval=TRUE, echo=FALSE} -dataset_vignette( - ae, - display_vars = exprs(USUBJID, AESTDTC, AEENDTC, AEDECOD, AEOUT), - filter = AEOUT == "FATAL" -) -``` - -```{r eval=TRUE} -src_ds <- dthcaus_source( - dataset_name = "ds", - filter = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), - date = DSSTDT, - mode = "first", - dthcaus = "Death in DS" -) -``` - -```{r, eval=TRUE, echo=FALSE} -dataset_vignette( - ds, - display_vars = exprs(USUBJID, DSDECOD, DSTERM, DSSTDTC), - filter = DSDECOD == "DEATH" -) -``` - -Once the sources are defined, the function `derive_var_dthcaus()` can be used to derive `DTHCAUS`: +An example call to `derive_vars_extreme_event()` would be: ```{r eval=TRUE} adsl <- adsl %>% - derive_var_dthcaus( - src_ae, src_ds, - source_datasets = list(ae = ae, ds = ds_ext) + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + condition = AEOUT == "FATAL", + set_values_to = exprs(DTHCAUS = AEDECOD), + ), + event( + dataset_name = "ds", + condition = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), + set_values_to = exprs(DTHCAUS = DSTERM), + ) + ), + source_datasets = list(ae = ae, ds = ds), + tmp_event_nr_var = event_nr, + order = exprs(event_nr), + mode = "first", + new_vars = exprs(DTHCAUS) ) ``` @@ -494,32 +462,30 @@ dataset_vignette( The function also offers the option to add some traceability variables (e.g. `DTHDOM` would store the domain where the date of death is collected, and `DTHSEQ` would store the `xxSEQ` value of -that domain). To add them, the `traceability_vars` argument must be added to the `dthcaus_source()` -arguments: +that domain). The traceability variables should be added to the `event()` calls and included in the `new_vars` parameter of `derive_vars_extreme_event()`. ```{r eval=TRUE} -src_ae <- dthcaus_source( - dataset_name = "ae", - filter = AEOUT == "FATAL", - date = convert_dtc_to_dtm(AESTDTC, highest_imputation = "M"), - mode = "first", - dthcaus = AEDECOD, - set_values_to = exprs(DTHDOM = "AE", DTHSEQ = AESEQ) -) - -src_ds <- dthcaus_source( - dataset_name = "ds", - filter = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), - date = DSSTDT, - mode = "first", - dthcaus = DSTERM, - set_values_to = exprs(DTHDOM = "DS", DTHSEQ = DSSEQ) -) adsl <- adsl %>% select(-DTHCAUS) %>% # remove it before deriving it again - derive_var_dthcaus( - src_ae, src_ds, - source_datasets = list(ae = ae, ds = ds_ext) + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + condition = AEOUT == "FATAL", + set_values_to = exprs(DTHCAUS = AEDECOD, DTHDOM = "AE", DTHSEQ = AESEQ), + ), + event( + dataset_name = "ds", + condition = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM), + set_values_to = exprs(DTHCAUS = DSTERM, DTHDOM = "DS", DTHSEQ = DSSEQ), + ) + ), + source_datasets = list(ae = ae, ds = ds), + tmp_event_nr_var = event_nr, + order = exprs(event_nr), + mode = "first", + new_vars = exprs(DTHCAUS, DTHDOM, DTHSEQ) ) ``` @@ -570,49 +536,54 @@ dataset_vignette( ## Derive the Last Date Known Alive (`LSTALVDT`) {#lstalvdt} Similarly as for the cause of death (`DTHCAUS`), the last known alive date -(`LSTALVDT`) can be derived from multiples sources and the user must ensure the -sources (`date_source()`) are correctly defined. - -`date_source()` specifications: - -- `dataset_name`: the name of the dataset where to search for date information, -- `filter`: the filter to apply on the datasets, -- `date`: the date of interest, -- `set_values_to`: whether the traceability variables need to be added (e.g -source domain, sequence, variable) +(`LSTALVDT`) can be derived from multiples sources using `derive_vars_extreme_event()`. An example could be (DTC dates are converted to numeric dates imputing missing day and month to the first): -```{r eval=TRUE} -ae_start_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AESTDTC, highest_imputation = "M") -) -ae_end_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AEENDTC, highest_imputation = "M") -) -lb_date <- date_source( - dataset_name = "lb", - date = convert_dtc_to_dt(LBDTC, highest_imputation = "M") -) -trt_end_date <- date_source( - dataset_name = "adsl", - date = TRTEDT -) -``` - -Once the sources are defined, the function `derive_var_extreme_dt()` can be used -to derive `LSTALVDT`: - ```{r eval=TRUE} adsl <- adsl %>% - derive_var_extreme_dt( - new_var = LSTALVDT, - ae_start_date, ae_end_date, lb_date, trt_end_date, - source_datasets = list(ae = ae, adsl = adsl, lb = lb), - mode = "last" + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + order = exprs(AESTDTC, AESEQ), + condition = !is.na(AESTDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AESTDTC, highest_imputation = "M"), + seq = AESEQ + ), + ), + event( + dataset_name = "ae", + order = exprs(AEENDTC, AESEQ), + condition = !is.na(AEENDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AEENDTC, highest_imputation = "M"), + seq = AESEQ + ), + ), + event( + dataset_name = "lb", + order = exprs(LBDTC, LBSEQ), + condition = !is.na(LBDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(LBDTC, highest_imputation = "M"), + seq = LBSEQ + ), + ), + event( + dataset_name = "adsl", + condition = !is.na(TRTEDT), + set_values_to = exprs(LSTALVDT = TRTEDT, seq = 0), + ) + ), + source_datasets = list(ae = ae, lb = lb, adsl = adsl), + tmp_event_nr_var = event_nr, + order = exprs(LSTALVDT, seq, event_nr), + mode = "last", + new_vars = exprs(LSTALVDT) ) ``` @@ -624,38 +595,58 @@ dataset_vignette( ) ``` -Similarly to `dthcaus_source()`, the traceability variables can be added by specifying the -`set_values_to` argument in `date_source()`. +Traceability variables can be added by specifying the variables in the `set_values_to` parameter of the `event()` function. ```{r eval=TRUE} -ae_start_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AESTDTC, highest_imputation = "M"), - set_values_to = exprs(LALVDOM = "AE", LALVSEQ = AESEQ, LALVVAR = "AESTDTC") -) -ae_end_date <- date_source( - dataset_name = "ae", - date = convert_dtc_to_dt(AEENDTC, highest_imputation = "M"), - set_values_to = exprs(LALVDOM = "AE", LALVSEQ = AESEQ, LALVVAR = "AEENDTC") -) -lb_date <- date_source( - dataset_name = "lb", - date = convert_dtc_to_dt(LBDTC, highest_imputation = "M"), - set_values_to = exprs(LALVDOM = "LB", LALVSEQ = LBSEQ, LALVVAR = "LBDTC") -) -trt_end_date <- date_source( - dataset_name = "adsl", - date = TRTEDTM, - set_values_to = exprs(LALVDOM = "ADSL", LALVSEQ = NA_integer_, LALVVAR = "TRTEDTM") -) - adsl <- adsl %>% select(-LSTALVDT) %>% # created in the previous call - derive_var_extreme_dt( - new_var = LSTALVDT, - ae_start_date, ae_end_date, lb_date, trt_end_date, - source_datasets = list(ae = ae, adsl = adsl, lb = lb), - mode = "last" + derive_vars_extreme_event( + by_vars = exprs(STUDYID, USUBJID), + events = list( + event( + dataset_name = "ae", + order = exprs(AESTDTC, AESEQ), + condition = !is.na(AESTDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AESTDTC, highest_imputation = "M"), + LALVSEQ = AESEQ, + LALVDOM = "AE", + LALVVAR = "AESTDTC" + ), + ), + event( + dataset_name = "ae", + order = exprs(AEENDTC, AESEQ), + condition = !is.na(AEENDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(AEENDTC, highest_imputation = "M"), + LALVSEQ = AESEQ, + LALVDOM = "AE", + LALVVAR = "AEENDTC" + ), + ), + event( + dataset_name = "lb", + order = exprs(LBDTC, LBSEQ), + condition = !is.na(LBDTC), + set_values_to = exprs( + LSTALVDT = convert_dtc_to_dt(LBDTC, highest_imputation = "M"), + LALVSEQ = LBSEQ, + LALVDOM = "LB", + LALVVAR = "LBDTC" + ), + ), + event( + dataset_name = "adsl", + condition = !is.na(TRTEDT), + set_values_to = exprs(LSTALVDT = TRTEDT, LALVSEQ = NA_integer_, LALVDOM = "ADSL", LALVVAR = "TRTEDTM"), + ) + ), + source_datasets = list(ae = ae, lb = lb, adsl = adsl), + tmp_event_nr_var = event_nr, + order = exprs(LSTALVDT, LALVSEQ, event_nr), + mode = "last", + new_vars = exprs(LSTALVDT, LALVSEQ, LALVDOM, LALVVAR) ) ```