Skip to content

Commit

Permalink
feat: #2142 remove extra fluff for missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed Nov 7, 2023
1 parent 85f4f9e commit b3fc993
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
8 changes: 4 additions & 4 deletions R/derive_param_exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
#'
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 8 additions & 20 deletions R/derive_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
#'
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -247,28 +247,16 @@ 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,
new_ref_obs
)
}

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
}
12 changes: 6 additions & 6 deletions man/derive_param_exposure.Rd

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

4 changes: 2 additions & 2 deletions man/derive_summary_records.Rd

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

0 comments on commit b3fc993

Please sign in to comment.