diff --git a/R/derive_extreme_event.R b/R/derive_extreme_event.R index bdf3f39e28..3067291c3d 100644 --- a/R/derive_extreme_event.R +++ b/R/derive_extreme_event.R @@ -340,7 +340,7 @@ #' ) %>% #' filter(PARAMCD == "CBOR") #' -derive_extreme_event <- function(dataset, +derive_extreme_event <- function(dataset = NULL, by_vars = NULL, events, tmp_event_nr_var = NULL, @@ -530,16 +530,6 @@ derive_extreme_event <- function(dataset, #' 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 keep_source_vars Variables to keep from the source dataset -#' -#' For each event the specified variables are kept from the selected -#' observations. The variables specified for `by_vars` 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 new_vars Variables to add #' #' The specified variables from the events are added to the output @@ -563,15 +553,12 @@ derive_extreme_event <- function(dataset, #' 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. Only the variables specified for the `keep_source_vars` field of the -#' event, and the by variables (`by_vars`) and the variables created by -#' `set_values_to` are kept. #' 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 `set_values_to` parameter are added to +#' 1. The variables specified by the `new_vars` parameter are added to #' the selected observations. #' 1. The variables are added to input dataset. #' @@ -642,9 +629,8 @@ derive_extreme_event <- function(dataset, #' ) #' ), #' source_datasets = list(adsl = adsl, lb = lb), -#' order = exprs(USUBJID, LSTALVDT, event_nr), +#' order = exprs(LSTALVDT, event_nr), #' mode = "last", -#' keep_source_vars = exprs(STUDYID, USUBJID), #' new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) #' ) #' @@ -656,9 +642,9 @@ derive_extreme_event <- function(dataset, #' "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", +#' ~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( @@ -688,9 +674,8 @@ derive_extreme_event <- function(dataset, #' ), #' source_datasets = list(ae = ae, ds = ds), #' tmp_event_nr_var = event_nr, -#' order = exprs(USUBJID, DTHDT, event_nr), +#' order = exprs(DTHDT, event_nr), #' mode = "first", -#' keep_source_vars = exprs(STUDYID, USUBJID), #' new_vars = exprs(DTHCAUS = DTHCAUS, DTHDT = DTHDT) #' ) derive_vars_extreme_event <- function(dataset, @@ -701,26 +686,26 @@ derive_vars_extreme_event <- function(dataset, mode, source_datasets = NULL, check_type = "warning", - new_vars, - keep_source_vars = by_vars) { + 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 = event_nr, + tmp_event_nr_var = !!tmp_event_nr_var, order = order, mode = mode, source_datasets = source_datasets, check_type = check_type, - set_values_to = new_vars, - keep_source_vars = keep_source_vars + set_values_to = new_vars ) derive_vars_merged( dataset, dataset_add = new_obs, + new_vars = new_vars, by_vars = by_vars ) } diff --git a/man/derive_extreme_event.Rd b/man/derive_extreme_event.Rd index 8bf5106b90..6c5bfb45fb 100644 --- a/man/derive_extreme_event.Rd +++ b/man/derive_extreme_event.Rd @@ -5,7 +5,7 @@ \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, diff --git a/man/derive_vars_extreme_event.Rd b/man/derive_vars_extreme_event.Rd index 71029e36f5..8f2064cd99 100644 --- a/man/derive_vars_extreme_event.Rd +++ b/man/derive_vars_extreme_event.Rd @@ -13,14 +13,13 @@ derive_vars_extreme_event( mode, source_datasets = NULL, check_type = "warning", - new_vars, - keep_source_vars = by_vars + new_vars ) } \arguments{ \item{dataset}{Input dataset -The variables specified by the \code{by_vars} and \code{order} argument(s) to be expected.} +The variables specified by the \code{by_vars} and \code{order} arguments are expected to be in the dataset.} \item{by_vars}{Grouping variables @@ -84,15 +83,6 @@ by variables and the order. 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( = )}.} - -\item{keep_source_vars}{Variables to keep from the source dataset - -For each event the specified variables are kept from the selected -observations. The variables specified for \code{by_vars} and created by -\code{set_values_to} are always kept. - -\emph{Permitted Values}: A list of expressions where each element is -a symbol or a tidyselect expression, e.g., \code{exprs(VISIT, VISITNUM, starts_with("RS"))}.} } \value{ The input dataset with the best or worst observation of each by group @@ -117,16 +107,13 @@ select the observations. 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 Only the variables specified for the \code{keep_source_vars} field of the -event, and the by variables (\code{by_vars}) and the variables created by -\code{set_values_to} are kept. } \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{set_values_to} parameter are added to +\item The variables specified by the \code{new_vars} parameter are added to the selected observations. \item The variables are added to input dataset. } @@ -187,9 +174,8 @@ derive_vars_extreme_event( ) ), source_datasets = list(adsl = adsl, lb = lb), - order = exprs(USUBJID, LSTALVDT, event_nr), + order = exprs(LSTALVDT, event_nr), mode = "last", - keep_source_vars = exprs(STUDYID, USUBJID), new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) ) @@ -201,9 +187,9 @@ adsl <- tribble( "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", + ~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( @@ -233,9 +219,8 @@ derive_vars_extreme_event( ), source_datasets = list(ae = ae, ds = ds), tmp_event_nr_var = event_nr, - order = exprs(USUBJID, DTHDT, event_nr), + order = exprs(DTHDT, event_nr), mode = "first", - keep_source_vars = exprs(STUDYID, USUBJID), new_vars = exprs(DTHCAUS = DTHCAUS, DTHDT = DTHDT) ) } diff --git a/man/dthcaus_source.Rd b/man/dthcaus_source.Rd index 6c3604b6cb..28c70caea5 100644 --- a/man/dthcaus_source.Rd +++ b/man/dthcaus_source.Rd @@ -92,19 +92,6 @@ Other superseded: \code{\link{derive_var_extreme_dtm}()}, \code{\link{derive_var_extreme_dt}()}, \code{\link{get_summary_records}()} - -Source Objects: -\code{\link{basket_select}()}, -\code{\link{censor_source}()}, -\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}()} } \concept{superseded} \keyword{superseded} diff --git a/man/flag_event.Rd b/man/flag_event.Rd index 338fd0660d..2f68b8284a 100644 --- a/man/flag_event.Rd +++ b/man/flag_event.Rd @@ -40,7 +40,6 @@ 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/tests/testthat/test-derive_extreme_event.R b/tests/testthat/test-derive_extreme_event.R index 3f653fa9ac..9c246fdec0 100644 --- a/tests/testthat/test-derive_extreme_event.R +++ b/tests/testthat/test-derive_extreme_event.R @@ -368,10 +368,8 @@ test_that("derive_extreme_event Test 5: derive_vars_extreme_event", { ) ), source_datasets = list(adsl = adsl), - tmp_event_nr_var = event_nr, - order = exprs(USUBJID, event_nr), - mode = "first", - keep_source_vars = exprs(STUDYID, USUBJID), + order = exprs(LSTALVDT), + mode = "last", new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) ) @@ -440,7 +438,7 @@ test_that("derive_extreme_event Test 6: Cover event$order", { event( dataset_name = "lb_ext", condition = !is.na(ADT), - order = exprs(ADT), + order = exprs(ADT, LBSEQ), mode = "last", set_values_to = exprs(LSTALVDT = ADT, DTHFL = "N") ), @@ -454,9 +452,8 @@ test_that("derive_extreme_event Test 6: Cover event$order", { ), source_datasets = list(adsl_ext = adsl_ext, lb_ext = lb_ext), tmp_event_nr_var = event_nr, - order = exprs(USUBJID, LSTALVDT, event_nr), + order = exprs(LSTALVDT, event_nr), mode = "last", - keep_source_vars = exprs(STUDYID, USUBJID), new_vars = exprs(LSTALVDT = LSTALVDT, DTHFL = DTHFL) )