Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2521 remove lifecycle deprecation code for get summary records #2568

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions R/get_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' see the `derive_summary_records()` function.
#'
#' @param dataset
#' `r roxygen_param_dataset(expected_vars = c("by_vars", "analysis_var"))`
#' `r roxygen_param_dataset(expected_vars = c("by_vars"))`
#'
#' @param by_vars Grouping variables
#'
Expand All @@ -38,18 +38,6 @@
#' + `filter_rows = (dplyr::n() > 2)` will filter n count of `by_vars` greater
#' than 2.
#'
#' @param analysis_var Analysis variable.
#'
#' `r lifecycle::badge("deprecated")` Please use `set_values_to` instead.
#'
#' @param summary_fun Function that takes as an input the `analysis_var` and
#' performs the calculation.
#'
#' `r lifecycle::badge("deprecated")` Please use `set_values_to` instead.
#'
#' This can include built-in functions as well as user defined functions,
#' for example `mean` or `function(x) mean(x, na.rm = TRUE)`.
#'
#' @param set_values_to Variables to be set
#'
#' The specified variables are set to the specified values for the new
Expand Down Expand Up @@ -160,8 +148,6 @@
get_summary_records <- function(dataset,
by_vars,
filter = NULL,
analysis_var,
summary_fun,
set_values_to = NULL) {
assert_vars(by_vars)
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
Expand All @@ -171,16 +157,6 @@ get_summary_records <- function(dataset,
check_is_grouped = FALSE
)
assert_varval_list(set_values_to)
if (!missing(analysis_var) || !missing(summary_fun)) {
deprecate_stop(
"1.1.0",
I("get_summary_records(anaylsis_var = , summary_fun = )"),
"get_summary_records(set_values_to = )"
)
analysis_var <- assert_symbol(enexpr(analysis_var))
assert_s3_class(summary_fun, "function")
set_values_to <- exprs(!!analysis_var := {{ summary_fun }}(!!analysis_var), !!!set_values_to)
}

# Summarise the analysis value
dataset %>%
Expand Down
23 changes: 2 additions & 21 deletions man/get_summary_records.Rd

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

68 changes: 68 additions & 0 deletions tests/testthat/test-get_summary_records.R
bms63 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,71 @@ test_that("get_summary_records Test 3: Compute avg AVAL only if >2 records withi
keys = c("USUBJID", "PARAM", "AVISIT")
)
})

# nolint start

## Test 4: Throw error if deprecated formal argument analysis_var used ----
test_that("get_summary_records Test 4: Show deprecated formal argument `analysis_var`
throws an error", {
# nolint end
input <- tibble::tribble(
~USUBJID, ~EGSEQ, ~PARAM, ~AVISIT, ~EGDTC, ~AVAL, ~TRTA,
"XYZ-1001", 1, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:50", 385, NA_character_,
"XYZ-1001", 2, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:52", 399, NA_character_,
"XYZ-1001", 3, "QTcF Int. (msec)", "Baseline", "2016-02-24T07:56", 396, NA_character_,
"XYZ-1001", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:45", 384, "Placebo",
"XYZ-1001", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:48", 393, "Placebo",
"XYZ-1001", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-08T09:51", 388, "Placebo",
"XYZ-1001", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:45", 385, "Placebo",
"XYZ-1001", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:48", 394, "Placebo",
"XYZ-1001", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-22T10:51", 402, "Placebo",
"XYZ-1002", 1, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 399, NA_character_,
"XYZ-1002", 2, "QTcF Int. (msec)", "Baseline", "2016-02-22T07:58", 410, NA_character_,
"XYZ-1002", 3, "QTcF Int. (msec)", "Baseline", "2016-02-22T08:01", 392, NA_character_,
"XYZ-1002", 4, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:50", 401, "Active 20mg",
"XYZ-1002", 5, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:53", 407, "Active 20mg",
"XYZ-1002", 6, "QTcF Int. (msec)", "Visit 2", "2016-03-06T09:56", 400, "Active 20mg",
"XYZ-1002", 7, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:50", 412, "Active 20mg",
"XYZ-1002", 8, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:53", 414, "Active 20mg",
"XYZ-1002", 9, "QTcF Int. (msec)", "Visit 3", "2016-03-24T10:56", 402, "Active 20mg"
)

expect_no_error(get_summary_records(
input,
by_vars = exprs(USUBJID, PARAM, AVISIT),
set_values_to = exprs(
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
)
))

# using deprecated arguments
expect_error(get_summary_records(
input,
by_vars = exprs(USUBJID, PARAM, AVISIT),
analysis_var = exprs(AVAL),
summary_fun = exprs(mean)
))

# using correct arguments, plus deprecated argument `analysis_var`
expect_error(get_summary_records(
input,
by_vars = exprs(USUBJID, PARAM, AVISIT),
set_values_to = exprs(
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
),
analysis_var = exprs(AVAL)
))

# using correct arguments, plus deprecated argument `summary_fun`
expect_error(get_summary_records(
input,
by_vars = exprs(USUBJID, PARAM, AVISIT),
set_values_to = exprs(
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
),
summary_fun = exprs(mean)
))
})
Loading