diff --git a/NEWS.md b/NEWS.md index a6e2dfb262..d366432902 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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) diff --git a/R/derive_param_exposure.R b/R/derive_param_exposure.R index 3c0e81c6b3..4b88da68f6 100644 --- a/R/derive_param_exposure.R +++ b/R/derive_param_exposure.R @@ -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)) @@ -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) @@ -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, diff --git a/R/derive_summary_records.R b/R/derive_summary_records.R index 453fba2cb4..ca2a3bc2e1 100644 --- a/R/derive_summary_records.R +++ b/R/derive_summary_records.R @@ -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) @@ -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 } diff --git a/inst/templates/ad_adeg.R b/inst/templates/ad_adeg.R index 7df467df42..4e574220d8 100644 --- a/inst/templates/ad_adeg.R +++ b/inst/templates/ad_adeg.R @@ -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" diff --git a/inst/templates/ad_advs.R b/inst/templates/ad_advs.R index 85f00152c6..191be64b22 100644 --- a/inst/templates/ad_advs.R +++ b/inst/templates/ad_advs.R @@ -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" diff --git a/man/derive_param_exposure.Rd b/man/derive_param_exposure.Rd index e54fd5704d..ff66659f43 100644 --- a/man/derive_param_exposure.Rd +++ b/man/derive_param_exposure.Rd @@ -11,6 +11,7 @@ derive_param_exposure( analysis_var, summary_fun, filter = NULL, + filter_add = NULL, set_values_to = NULL ) } diff --git a/man/derive_summary_records.Rd b/man/derive_summary_records.Rd index e4d8da4c9e..311e2f0e9d 100644 --- a/man/derive_summary_records.Rd +++ b/man/derive_summary_records.Rd @@ -5,11 +5,12 @@ \title{Add New Records Within By Groups Using Aggregation Functions} \usage{ derive_summary_records( - dataset, + dataset = NULL, dataset_add = NULL, dataset_ref = NULL, by_vars, filter = NULL, + filter_add = NULL, analysis_var, summary_fun, set_values_to = NULL, diff --git a/tests/testthat/test-call_derivation.R b/tests/testthat/test-call_derivation.R index c5e9e10abc..a2c0484ca7 100644 --- a/tests/testthat/test-call_derivation.R +++ b/tests/testthat/test-call_derivation.R @@ -10,7 +10,7 @@ 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), @@ -18,7 +18,7 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected 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), @@ -26,7 +26,7 @@ test_that("call_derivation Test 1: Test that call_derivation generates expected VSSTRESN = min(VSSTRESN, na.rm = TRUE), DTYPE = "MINIMUM" ), - filter = dplyr::n() >= 2L + filter_add = dplyr::n() >= 2L ) actual_output <- call_derivation( @@ -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( diff --git a/tests/testthat/test-compute_scale.R b/tests/testthat/test-compute_scale.R index afb20f819f..74ae6d7ec9 100644 --- a/tests/testthat/test-compute_scale.R +++ b/tests/testthat/test-compute_scale.R @@ -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" diff --git a/tests/testthat/test-derive_summary_records.R b/tests/testthat/test-derive_summary_records.R index 69fb2f6d3d..78bf2bc614 100644 --- a/tests/testthat/test-derive_summary_records.R +++ b/tests/testthat/test-derive_summary_records.R @@ -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), diff --git a/vignettes/questionnaires.Rmd b/vignettes/questionnaires.Rmd index 5a1b353e70..dc24569f09 100644 --- a/vignettes/questionnaires.Rmd +++ b/vignettes/questionnaires.Rmd @@ -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", @@ -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, @@ -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, @@ -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)),