Skip to content

Commit

Permalink
feat: #2142 rename filter to filter_add
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed Nov 3, 2023
1 parent 6ee8500 commit 19ced77
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ for the event number, which can be used in `order`. (#2140)
`analysis_var` and `summary_fun` were deprecated in favor of `set_values_to`.
(#1792)

- In `derive_summary_records()` and `derive_param_exposure()` the argument `filter` was renamed to `filter_add` (#2142)

- In `derive_var_merged_summary()` the arguments `new_var`, `analysis_var`, and
`summary_fun` were deprecated in favor of `new_vars`. (#1792)

Expand Down
13 changes: 11 additions & 2 deletions R/derive_param_exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ derive_param_exposure <- function(dataset,
analysis_var,
summary_fun,
filter = NULL,
filter_add = NULL,
set_values_to = NULL) {
by_vars <- assert_vars(by_vars)
analysis_var <- assert_symbol(enexpr(analysis_var))
Expand Down Expand Up @@ -158,7 +159,15 @@ derive_param_exposure <- function(dataset,
assert_data_frame(dataset,
required_vars = expr_c(by_vars, analysis_var, exprs(PARAMCD), dates)
)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
if (!missing(filter)) {
deprecate_warn(
"1.0.0",
I("derive_param_exposure(filter = )"),
"derive_param_exposure(filter_add = )"
)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
}
filter <- assert_filter_cond(enexpr(filter_add), optional = TRUE)
assert_varval_list(set_values_to, required_elements = "PARAMCD")
assert_param_does_not_exist(dataset, set_values_to$PARAMCD)
assert_character_scalar(input_code)
Expand All @@ -173,7 +182,7 @@ derive_param_exposure <- function(dataset,
derive_summary_records(
dataset,
by_vars = by_vars,
filter = PARAMCD == !!input_code & !!filter,
filter_add = PARAMCD == !!input_code & !!filter,
set_values_to = exprs(
!!analysis_var := {{ summary_fun }}(!!analysis_var),
!!!set_dtm,
Expand Down
14 changes: 12 additions & 2 deletions R/derive_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@
#' )
#' ) %>%
#' arrange(USUBJID, AVISIT)
derive_summary_records <- function(dataset,
derive_summary_records <- function(dataset = NULL,
dataset_add = NULL,
dataset_ref = NULL,
by_vars,
filter = NULL,
filter_add = NULL,
analysis_var,
summary_fun,
set_values_to = NULL,
missing_values = NULL) {
assert_vars(by_vars)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
assert_data_frame(
dataset,
required_vars = expr_c(by_vars)
Expand Down Expand Up @@ -204,6 +204,16 @@ derive_summary_records <- function(dataset,
set_values_to <- exprs(!!analysis_var := {{ summary_fun }}(!!analysis_var), !!!set_values_to)
}

if (!missing(filter)) {
deprecate_warn(
"1.0.0",
I("derive_summary_records(filter = )"),
"derive_summary_records(filter_add = )"
)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
}
filter <- assert_filter_cond(enexpr(filter_add), optional = TRUE)

if (is.null(dataset_add)) {
dataset_add <- dataset
}
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/ad_adeg.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ adeg <- adeg %>%
adeg <- adeg %>%
derive_summary_records(
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, AVISITN, AVISIT, ADT),
filter = dplyr::n() >= 2 & PARAMCD != "EGINTP",
filter_add = dplyr::n() >= 2 & PARAMCD != "EGINTP",
set_values_to = exprs(
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/ad_advs.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ advs <- advs %>%
advs <- advs %>%
derive_summary_records(
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, PARAMCD, AVISITN, AVISIT, ADT, ADY),
filter = !is.na(AVAL),
filter_add = !is.na(AVAL),
set_values_to = exprs(
AVAL = mean(AVAL),
DTYPE = "AVERAGE"
Expand Down
1 change: 1 addition & 0 deletions man/derive_param_exposure.Rd

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

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

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

8 changes: 4 additions & 4 deletions tests/testthat/test-call_derivation.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected
VSSTRESN = mean(VSSTRESN, na.rm = TRUE),
DTYPE = "AVERAGE"
),
filter = dplyr::n() >= 2L
filter_add = dplyr::n() >= 2L
) %>%
derive_summary_records(
by_vars = exprs(USUBJID, VSTESTCD),
set_values_to = exprs(
VSSTRESN = max(VSSTRESN, na.rm = TRUE),
DTYPE = "MAXIMUM"
),
filter = dplyr::n() >= 2L
filter_add = dplyr::n() >= 2L
) %>%
derive_summary_records(
by_vars = exprs(USUBJID, VSTESTCD),
set_values_to = exprs(
VSSTRESN = min(VSSTRESN, na.rm = TRUE),
DTYPE = "MINIMUM"
),
filter = dplyr::n() >= 2L
filter_add = dplyr::n() >= 2L
)

actual_output <- call_derivation(
Expand All @@ -53,7 +53,7 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected
)
),
by_vars = exprs(USUBJID, VSTESTCD),
filter = dplyr::n() >= 2L
filter_add = dplyr::n() >= 2L
)

expect_dfs_equal(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-compute_scale.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test_that("compute_scale Test 5: compute_scale() works as expected within
derive_summary_records(
input,
by_vars = exprs(STUDYID, USUBJID, AVISIT, AVISITN),
filter = (PARAMCD %in% c("ITEM1", "ITEM2", "ITEM3")),
filter_add = (PARAMCD %in% c("ITEM1", "ITEM2", "ITEM3")),
set_values_to = exprs(
AVAL = compute_scale(AVAL, c(1, 5), c(0, 100), flip_direction = TRUE, min_n = 3),
PARAMCD = "ITEMAVG"
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-derive_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("derive_summary_records Test 2: Filter record within `by_vars`", {
actual_output <- input %>%
derive_summary_records(
by_vars = exprs(subj, visit),
filter = n() > 2,
filter_add = n() > 2,
set_values_to = exprs(
val = mean(val),
seq = max(seq),
Expand Down
8 changes: 4 additions & 4 deletions vignettes/questionnaires.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ adgad7 <- adqs %>%
derive_summary_records(
by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS),
# Select records contributing to total score
filter = str_detect(PARAMCD, "GAD020[1-7]"),
filter_add = str_detect(PARAMCD, "GAD020[1-7]"),
set_values_to = exprs(
AVAL = sum(AVAL, na.rm = TRUE),
PARAMCD = "GAD02TS",
Expand Down Expand Up @@ -171,7 +171,7 @@ adgdssf <- adqs %>%
derive_summary_records(
by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS),
# Select records contributing to total score
filter = str_detect(PARAMCD, "GDS02[01][0-9]"),
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
set_values_to = exprs(
AVAL = compute_scale(
AVAL,
Expand Down Expand Up @@ -518,7 +518,7 @@ be derived by `derive_summary_records()`.
```{r}
adgdssf <- adgdssf %>%
derive_summary_records(
filter = str_detect(PARAMCD, "GDS02[01][0-9]"),
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
by_vars = exprs(USUBJID, AVISIT),
set_values_to = exprs(
AVAL = sum(!is.na(AVAL)) / 15 >= 0.9,
Expand Down Expand Up @@ -567,7 +567,7 @@ adgdssf <- adgdssf %>%
)
) %>%
derive_summary_records(
filter = str_detect(PARAMCD, "GDS02[01][0-9]"),
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
by_vars = exprs(USUBJID, AVISIT),
set_values_to = exprs(
AVAL = all(!is.na(AVAL)),
Expand Down

0 comments on commit 19ced77

Please sign in to comment.