diff --git a/R/derive_param_exposure.R b/R/derive_param_exposure.R index a21e8c1d32..11552b94ed 100644 --- a/R/derive_param_exposure.R +++ b/R/derive_param_exposure.R @@ -6,11 +6,11 @@ #' @param dataset #' `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var"))` #' `PARAMCD` is expected as well, -#' + Either `ASTDTM` and `AENDTM` or `ASTDT` and `AENDT` are also expected. #' #' @param dataset_add Additional dataset #' -#' The variables specified for `by_vars` are expected. +#' The variables specified for `by_vars`, `analysis_var`, +#' + alongside either `ASTDTM` and `AENDTM` or `ASTDT` and `AENDT` are also expected. #' Observations from the specified dataset are going to be used to calculate and added #' as new records to the input dataset (`dataset`). #' @@ -187,10 +187,10 @@ derive_param_exposure <- function(dataset = NULL, ) } - assert_data_frame(dataset, + assert_data_frame(dataset, required_vars = by_vars, optional = TRUE) + assert_data_frame(dataset_add, required_vars = expr_c(by_vars, analysis_var, exprs(PARAMCD), dates) ) - assert_data_frame(dataset_add, required_vars = by_vars) if (!missing(filter)) { deprecate_warn( diff --git a/R/derive_summary_records.R b/R/derive_summary_records.R index 9e983c4034..77e8a7d8a9 100644 --- a/R/derive_summary_records.R +++ b/R/derive_summary_records.R @@ -78,7 +78,7 @@ #' #' @param missing_values Values for missing summary values #' -#' For observations of the input dataset (`dataset`) or (`dataset_add`) which do not have a +#' For observations of the reference dataset (`dataset_ref`) which do not have a #' complete mapping defined by the summarization defined in `set_values_to`. Only variables #' specified for `set_values_to` can be specified for `missing_values`. #' @@ -176,7 +176,7 @@ #' adeg, #' dataset_add = adeg, #' by_vars = exprs(USUBJID, PARAM, AVISIT), -#' filter = n() > 2, +#' filter_add = n() > 2, #' set_values_to = exprs( #' AVAL = mean(AVAL, na.rm = TRUE), #' DTYPE = "AVERAGE" @@ -194,7 +194,7 @@ derive_summary_records <- function(dataset = NULL, set_values_to, missing_values = NULL) { assert_vars(by_vars) - assert_data_frame(dataset, required_vars = by_vars) + assert_data_frame(dataset, required_vars = by_vars, optional = TRUE) assert_data_frame(dataset_add, required_vars = by_vars) assert_data_frame( dataset_ref, @@ -247,10 +247,10 @@ derive_summary_records <- function(dataset = NULL, by = map_chr(by_vars, as_name) ) - tmp_ref_obs <- get_new_tmp_var(new_ref_obs, prefix = "tmp_ref_obs") - - new_ref_obs <- new_ref_obs %>% - mutate(!!tmp_ref_obs := 1L) + if (!is.null(missing_values)) { + new_ref_obs <- new_ref_obs %>% + mutate(!!!missing_values) + } df_return <- bind_rows( df_return, @@ -258,17 +258,5 @@ derive_summary_records <- function(dataset = NULL, ) } - if (!is.null(missing_values)) { - update_missings <- map2( - syms(names(missing_values)), - missing_values, - ~ expr(if_else(is.na(!!.x) & tmp_ref_obs_1 == 1, !!.y, !!.x)) - ) - names(update_missings) <- names(missing_values) - df_return <- df_return %>% - mutate(!!!update_missings) - } - - df_return %>% - remove_tmp_vars() + df_return } diff --git a/man/derive_param_exposure.Rd b/man/derive_param_exposure.Rd index 88092ca61f..9199ebd5d8 100644 --- a/man/derive_param_exposure.Rd +++ b/man/derive_param_exposure.Rd @@ -20,16 +20,16 @@ derive_param_exposure( \item{dataset}{Input dataset The variables specified by the \code{by_vars} and \code{analysis_var} argument(s) to be expected. -\code{PARAMCD} is expected as well, -\itemize{ -\item Either \code{ASTDTM} and \code{AENDTM} or \code{ASTDT} and \code{AENDT} are also expected. -}} +\code{PARAMCD} is expected as well,} \item{dataset_add}{Additional dataset -The variables specified for \code{by_vars} are expected. +The variables specified for \code{by_vars}, \code{analysis_var}, +\itemize{ +\item alongside either \code{ASTDTM} and \code{AENDTM} or \code{ASTDT} and \code{AENDT} are also expected. Observations from the specified dataset are going to be used to calculate and added -as new records to the input dataset (\code{dataset}).} +as new records to the input dataset (\code{dataset}). +}} \item{by_vars}{Grouping variables diff --git a/man/derive_summary_records.Rd b/man/derive_summary_records.Rd index 588f2d5599..793a2a2c5b 100644 --- a/man/derive_summary_records.Rd +++ b/man/derive_summary_records.Rd @@ -101,7 +101,7 @@ For example: \item{missing_values}{Values for missing summary values -For observations of the input dataset (\code{dataset}) or (\code{dataset_add}) which do not have a +For observations of the reference dataset (\code{dataset_ref}) which do not have a complete mapping defined by the summarization defined in \code{set_values_to}. Only variables specified for \code{set_values_to} can be specified for \code{missing_values}. @@ -202,7 +202,7 @@ derive_summary_records( adeg, dataset_add = adeg, by_vars = exprs(USUBJID, PARAM, AVISIT), - filter = n() > 2, + filter_add = n() > 2, set_values_to = exprs( AVAL = mean(AVAL, na.rm = TRUE), DTYPE = "AVERAGE"