From 8d56877c59cb0220c1f0e9a6901f77c55cdaa467 Mon Sep 17 00:00:00 2001 From: Sadchla Mascary <112789549+sadchla-codes@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:31:54 -0400 Subject: [PATCH] Closes # 459 keeping the documentation of the deprecated functions/arguments up to date (#464) * Closes # 459 keeping the documentation of the deprecated functions/argument up to date * updating styler --- NAMESPACE | 3 - NEWS.md | 12 + R/assertions.R | 67 ---- R/dev_utilities.R | 12 +- R/get.R | 12 +- R/quo.R | 12 +- man/assert_function_param.Rd | 29 -- man/assert_has_variables.Rd | 32 -- man/assert_named_exprs.Rd | 30 -- man/get_source_vars.Rd | 4 +- man/replace_values_by_names.Rd | 4 +- man/vars2chr.Rd | 4 +- tests/testthat/_snaps/assertions.md | 88 ++--- tests/testthat/test-assertions.R | 477 ++++++++++------------------ 14 files changed, 236 insertions(+), 550 deletions(-) delete mode 100644 man/assert_function_param.Rd delete mode 100644 man/assert_has_variables.Rd delete mode 100644 man/assert_named_exprs.Rd diff --git a/NAMESPACE b/NAMESPACE index b7fe577e..49577b20 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,14 +15,11 @@ export(assert_expr) export(assert_expr_list) export(assert_filter_cond) export(assert_function) -export(assert_function_param) -export(assert_has_variables) export(assert_integer_scalar) export(assert_list_element) export(assert_list_of) export(assert_logical_scalar) export(assert_named) -export(assert_named_exprs) export(assert_numeric_vector) export(assert_one_to_one) export(assert_param_does_not_exist) diff --git a/NEWS.md b/NEWS.md index 4dccd55b..be4cbab7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,18 @@ ## Breaking Changes +- The following functions are entering the next phase of the deprecation process: (#459) + +### Phase 1 (warning) + +### Phase 2 (error) + +### Phase 3 (removed) + - The argument `quosures` was removed in the functions `vars2chr(quosures)`, `replace_values_by_names(quosures)`, and `get_source_vars(quosures)` + - Removed at v1.0.0 `assert_named_expr()` + - Removed at v1.0.0 `assert_has_variables()` + - Removed at v1.0.0 `assert_function_param()` + ## Documentation ## Other diff --git a/R/assertions.R b/R/assertions.R index 004a05b8..10d8751b 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -1000,51 +1000,6 @@ assert_named <- function(arg, optional = FALSE, ) } -#' Assert Argument is a Named List of Expressions -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `assert_expr_list()` instead. -#' -#' @inheritParams assert_data_frame -#' -#' @keywords deprecated -#' @family deprecated -#' -#' @return -#' The function throws an error if `arg` is not a named `list` of expression or -#' returns the input invisibly otherwise -#' -#' @export -assert_named_exprs <- function(arg, optional = FALSE) { - deprecate_stop("0.5.0", "assert_named_exprs()", "assert_expr_list()") -} - -#' Does a Dataset Contain All Required Variables? -#' -#' Checks if a dataset contains all required variables -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `assert_data_frame()` instead. -#' -#' @param dataset A `data.frame` -#' @param required_vars A `character` vector of variable names -#' -#' -#' @return The function throws an error if any of the required variables are -#' missing in the input dataset. Otherwise, the dataset is returned invisibly. -#' -#' @export -#' -#' @keywords deprecated -#' @family deprecated -assert_has_variables <- function(dataset, required_vars) { - deprecate_stop("0.5.0", "assert_has_variables()", "assert_data_frame()") -} - #' Is Argument a Function? #' #' Checks if the argument is a function and if all expected arguments are @@ -1139,28 +1094,6 @@ assert_function <- function(arg, invisible(arg) } -#' Assert Argument is a Parameter of a Function -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is *deprecated*, please use `assert_function()` instead. -#' -#' @param arg The name of a function passed as a string -#' @param params A character vector of function parameters -#' -#' @keywords deprecated -#' @family deprecated -#' -#' @return -#' The function throws an error if any elements of `params` is not an argument of -#' the function given by `arg` -#' -#' @export -assert_function_param <- function(arg, params) { - deprecate_stop("0.5.0", "assert_function_param()", "assert_function()") -} - #' Asserts That a Parameter is Provided in the Expected Unit #' #' Checks if a parameter (`PARAMCD`) in a dataset is provided in the expected diff --git a/R/dev_utilities.R b/R/dev_utilities.R index 55d33cbc..cd79a208 100644 --- a/R/dev_utilities.R +++ b/R/dev_utilities.R @@ -152,11 +152,8 @@ contains_vars <- function(arg) { #' #' @param expressions A `list` of expressions created using [`exprs()`] #' -#' @param quosures *Deprecated*, please use `expressions` instead. -#' #' @return A character vector #' -#' #' @export #' #' @keywords dev_utility @@ -167,14 +164,7 @@ contains_vars <- function(arg) { #' library(rlang) #' #' vars2chr(exprs(USUBJID, AVAL)) -vars2chr <- function(expressions, quosures) { - if (!missing(quosures)) { - deprecate_stop( - "0.10.0", - "vars2chr(quosures = )", - "vars2chr(expressions = )" - ) - } +vars2chr <- function(expressions) { rlang::set_names( map_chr(expressions, as_string), names(expressions) diff --git a/R/get.R b/R/get.R index c209a564..4474165d 100644 --- a/R/get.R +++ b/R/get.R @@ -76,22 +76,12 @@ get_duplicates <- function(x) { #' #' @param expressions A list of expressions #' -#' @param quosures *Deprecated*, please use `expressions` instead. -#' -#' #' @keywords get #' @family get #' #' @return A list of expressions #' @export -get_source_vars <- function(expressions, quosures) { - if (!missing(quosures)) { - deprecate_stop( - "0.10.0", - "get_source_vars(quosures = )", - "get_source_vars(expressions = )" - ) - } +get_source_vars <- function(expressions) { assert_varval_list(expressions, optional = TRUE) source_vars <- expr_c(expressions)[lapply(expr_c(expressions), is.symbol) == TRUE] diff --git a/R/quo.R b/R/quo.R index 10fccb9f..06ba4b99 100644 --- a/R/quo.R +++ b/R/quo.R @@ -30,9 +30,6 @@ expr_c <- function(...) { #' #' @param expressions A list of expressions #' -#' @param quosures *Deprecated*, please use `expressions` instead. -#' -#' #' @keywords quo #' @family quo #' @@ -43,14 +40,7 @@ expr_c <- function(...) { #' @examples #' library(rlang) #' replace_values_by_names(exprs(AVAL, ADT = convert_dtc_to_dt(EXSTDTC))) -replace_values_by_names <- function(expressions, quosures) { - if (!missing(quosures)) { - deprecate_stop( - "0.3.0", - "replace_values_by_names(quosures = )", - "replace_values_by_names(expressions = )" - ) - } +replace_values_by_names <- function(expressions) { if (is.null(names(expressions))) { return(expressions) } diff --git a/man/assert_function_param.Rd b/man/assert_function_param.Rd deleted file mode 100644 index 06835610..00000000 --- a/man/assert_function_param.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/assertions.R -\name{assert_function_param} -\alias{assert_function_param} -\title{Assert Argument is a Parameter of a Function} -\usage{ -assert_function_param(arg, params) -} -\arguments{ -\item{arg}{The name of a function passed as a string} - -\item{params}{A character vector of function parameters} -} -\value{ -The function throws an error if any elements of \code{params} is not an argument of -the function given by \code{arg} -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{assert_function()} instead. -} -\seealso{ -Other deprecated: -\code{\link{assert_has_variables}()}, -\code{\link{assert_named_exprs}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/assert_has_variables.Rd b/man/assert_has_variables.Rd deleted file mode 100644 index 6fa7795f..00000000 --- a/man/assert_has_variables.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/assertions.R -\name{assert_has_variables} -\alias{assert_has_variables} -\title{Does a Dataset Contain All Required Variables?} -\usage{ -assert_has_variables(dataset, required_vars) -} -\arguments{ -\item{dataset}{A \code{data.frame}} - -\item{required_vars}{A \code{character} vector of variable names} -} -\value{ -The function throws an error if any of the required variables are -missing in the input dataset. Otherwise, the dataset is returned invisibly. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{assert_data_frame()} instead. -} -\details{ -Checks if a dataset contains all required variables -} -\seealso{ -Other deprecated: -\code{\link{assert_function_param}()}, -\code{\link{assert_named_exprs}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/assert_named_exprs.Rd b/man/assert_named_exprs.Rd deleted file mode 100644 index a4bd9f8a..00000000 --- a/man/assert_named_exprs.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/assertions.R -\name{assert_named_exprs} -\alias{assert_named_exprs} -\title{Assert Argument is a Named List of Expressions} -\usage{ -assert_named_exprs(arg, optional = FALSE) -} -\arguments{ -\item{arg}{A function argument to be checked} - -\item{optional}{Is the checked argument optional? If set to \code{FALSE} and \code{arg} -is \code{NULL} then an error is thrown} -} -\value{ -The function throws an error if \code{arg} is not a named \code{list} of expression or -returns the input invisibly otherwise -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is \emph{deprecated}, please use \code{assert_expr_list()} instead. -} -\seealso{ -Other deprecated: -\code{\link{assert_function_param}()}, -\code{\link{assert_has_variables}()} -} -\concept{deprecated} -\keyword{deprecated} diff --git a/man/get_source_vars.Rd b/man/get_source_vars.Rd index 45797a0c..30704bd1 100644 --- a/man/get_source_vars.Rd +++ b/man/get_source_vars.Rd @@ -4,12 +4,10 @@ \alias{get_source_vars} \title{Get Source Variables from a List of Expressions} \usage{ -get_source_vars(expressions, quosures) +get_source_vars(expressions) } \arguments{ \item{expressions}{A list of expressions} - -\item{quosures}{\emph{Deprecated}, please use \code{expressions} instead.} } \value{ A list of expressions diff --git a/man/replace_values_by_names.Rd b/man/replace_values_by_names.Rd index 0ad71aa3..a9750de7 100644 --- a/man/replace_values_by_names.Rd +++ b/man/replace_values_by_names.Rd @@ -4,12 +4,10 @@ \alias{replace_values_by_names} \title{Replace Expression Value with Name} \usage{ -replace_values_by_names(expressions, quosures) +replace_values_by_names(expressions) } \arguments{ \item{expressions}{A list of expressions} - -\item{quosures}{\emph{Deprecated}, please use \code{expressions} instead.} } \value{ A list of expressions diff --git a/man/vars2chr.Rd b/man/vars2chr.Rd index 15d59450..35361381 100644 --- a/man/vars2chr.Rd +++ b/man/vars2chr.Rd @@ -4,12 +4,10 @@ \alias{vars2chr} \title{Turn a List of Expressions into a Character Vector} \usage{ -vars2chr(expressions, quosures) +vars2chr(expressions) } \arguments{ \item{expressions}{A \code{list} of expressions created using \code{\link[=exprs]{exprs()}}} - -\item{quosures}{\emph{Deprecated}, please use \code{expressions} instead.} } \value{ A character vector diff --git a/tests/testthat/_snaps/assertions.md b/tests/testthat/_snaps/assertions.md index 3ceed2f5..771f4752 100644 --- a/tests/testthat/_snaps/assertions.md +++ b/tests/testthat/_snaps/assertions.md @@ -1,4 +1,4 @@ -# assert_filter_cond Test 3: `assert_filter_cond` works as expected +# assert_filter_cond Test 1: `assert_filter_cond` works as expected Code assert_filter_cond(arg = fc) @@ -6,7 +6,7 @@ Error: ! Argument `fc` must be a filter condition, but is a string -# assert_data_frame Test 4: error if not a dataframe +# assert_data_frame Test 2: error if not a dataframe Code example_fun(c(1, 2, 3)) @@ -14,7 +14,7 @@ Error in `example_fun()`: ! Argument `dataset` must be class , but is a double vector. -# assert_data_frame Test 7: error if dataframe is grouped +# assert_data_frame Test 5: error if dataframe is grouped Code example_fun(data) @@ -22,7 +22,7 @@ Error in `example_fun()`: ! Argument `dataset` must not be a grouped dataset, please `ungroup()` it. -# assert_data_frame Test 8: error if an expected variable is missing +# assert_data_frame Test 6: error if an expected variable is missing Code example_fun(data) @@ -30,7 +30,7 @@ Error in `example_fun()`: ! Required variable `USUBJID` is missing in `dataset` -# assert_data_frame Test 9: error if expected variables are missing +# assert_data_frame Test 7: error if expected variables are missing Code example_fun(data) @@ -38,7 +38,7 @@ Error in `example_fun()`: ! Required variables `STUDYID` and `USUBJID` are missing in `dataset` -# assert_character_scalar Test 15: error if `arg` not in values +# assert_character_scalar Test 13: error if `arg` not in values Code check_unit("month") @@ -54,7 +54,7 @@ Error in `check_unit2()`: ! Argument `duration_unit` must be equal to one of "YEARS", "MONTHS", "WEEKS", "DAYS", "HOURS", "MINUTES", or "SECONDS". -# assert_character_scalar Test 16: error if not character +# assert_character_scalar Test 14: error if not character Code example_fun2(2) @@ -62,7 +62,7 @@ Error in `example_fun2()`: ! Argument `msg_type` must be a scalar of class , but is a number. -# assert_character_scalar Test 17: error if input is a vector +# assert_character_scalar Test 15: error if input is a vector Code example_fun2(c("admiral", "admiralonco")) @@ -70,7 +70,7 @@ Error in `example_fun2()`: ! Argument `msg_type` must be a scalar of class , but is length 2 -# assert_character_vector Test 18: error if `arg` not a character vector +# assert_character_vector Test 16: error if `arg` not a character vector Code assert_character_vector(arg) @@ -78,7 +78,7 @@ Error: ! Argument `arg` must be , but is a double vector. -# assert_character_vector Test 19: error if `arg` is not in values +# assert_character_vector Test 17: error if `arg` is not in values Code example_fun(character = c("oak", "mint")) @@ -86,7 +86,7 @@ Error in `example_fun()`: ! Argument `character` must be with values "test" and "oak". -# assert_character_vector Test 20: arg_name correctly displayed in name check +# assert_character_vector Test 18: arg_name correctly displayed in name check Code example_fun(character = c(tree = "oak", "test")) @@ -95,7 +95,7 @@ ! All elements of `character` argument must be named. i The indices of the unnamed elements are 2 -# assert_logical_scalar Test 22: error if `arg` is not TRUE or FALSE +# assert_logical_scalar Test 20: error if `arg` is not TRUE or FALSE Code example_fun("test") @@ -103,7 +103,7 @@ Error in `example_fun()`: ! Argument `arg` must be either TRUE or FALSE, but is a string. -# assert_symbol Test 24: `assert_symbol` throws an error if `arg` is missing +# assert_symbol Test 22: `assert_symbol` throws an error if `arg` is missing Code example_fun(f()) @@ -111,7 +111,7 @@ Error in `example_fun()`: ! Argument `arg` must be a , but is missing. -# assert_symbol Test 25: `assert_symbol` throws an error if `arg` is not a symbol +# assert_symbol Test 23: `assert_symbol` throws an error if `arg` is not a symbol Code example_fun(f(NULL)) @@ -119,7 +119,7 @@ Error in `example_fun()`: ! Argument `arg` must be a , but is NULL. -# assert_expr Test 29: `assert_expr` throws an error if `arg` is missing +# assert_expr Test 27: `assert_expr` throws an error if `arg` is missing Code assert_expr() @@ -135,7 +135,7 @@ Error in `example_fun()`: ! Argument `data` cannot be missing. -# assert_expr Test 30: `assert_expr` throws an error if `arg` is not an expression +# assert_expr Test 28: `assert_expr` throws an error if `arg` is not an expression Code var <- c(1, 2) @@ -144,7 +144,7 @@ Error: ! Argument `var` must be an expression, but is a double vector -# assert_vars Test 32: error if unexpected input +# assert_vars Test 30: error if unexpected input Code assert_vars(AVAL + 1) @@ -187,7 +187,7 @@ ! All elements of `exprs(APERSDT = APxxSDT, APxxEDT)` argument must be named. i The indices of the unnamed elements are 2 -# assert_vars Test 33: error if some elements of `arg` are not unquoted variable names +# assert_vars Test 31: error if some elements of `arg` are not unquoted variable names Code example_fun(exprs(USUBJID, PARAMCD, NULL)) @@ -196,7 +196,7 @@ ! Each element of the list in argument `arg` must be class/type . i But, element 3 is NULL -# assert_integer_scalar Test 35: error if chosen subset not in subsets +# assert_integer_scalar Test 33: error if chosen subset not in subsets Code example_fun(1) @@ -204,7 +204,7 @@ Error in `assert_integer_scalar()`: ! Argument `subset` must be equal to one of "positive", "non-negative", "negative", or "none". -# assert_integer_scalar Test 37: error if `arg` is not an integer scalar +# assert_integer_scalar Test 35: error if `arg` is not an integer scalar Code example_fun(1.5) @@ -212,7 +212,7 @@ Error in `example_fun()`: ! Argument `arg` must be an integer scalar. -# assert_numeric_vector Test 39: error if `arg` is not a numeric vector +# assert_numeric_vector Test 37: error if `arg` is not a numeric vector Code example_fun(TRUE) @@ -236,7 +236,7 @@ Error in `example_fun()`: ! Argument `arg` must be a numeric vector, but it is a string. -# assert_s3_class Test 40: error if `arg` is not an object of a specific class S3 +# assert_s3_class Test 38: error if `arg` is not an object of a specific class S3 Code example_fun("test") @@ -244,7 +244,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is a string. -# assert_s3_class Test 42: error if `arg` is NULL and optional is FALSE +# assert_s3_class Test 40: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -252,7 +252,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is NULL. -# assert_list_of Test 44: error if `arg` is not a list of specific class S3 objects +# assert_list_of Test 42: error if `arg` is not a list of specific class S3 objects Code example_fun(list("test")) @@ -261,7 +261,7 @@ ! Each element of the list in argument `arg` must be class/type . i But, element 1 is a string -# assert_list_of Test 46: error if `arg` is NULL and optional is FALSE +# assert_list_of Test 44: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -269,7 +269,7 @@ Error in `example_fun()`: ! Argument `arg` must be class , but is NULL. -# assert_list_of Test 48: error if `arg` is not a named list (no elements named) +# assert_list_of Test 46: error if `arg` is not a named list (no elements named) Code mylist <- list(1, 2, 3) @@ -279,7 +279,7 @@ ! All elements of `mylist` argument must be named. i The indices of the unnamed elements are 1, 2, and 3 -# assert_list_of Test 49: error if `arg` is not a named list (some elements named) +# assert_list_of Test 47: error if `arg` is not a named list (some elements named) Code mylist <- list(1, 2, 3, d = 4) @@ -289,7 +289,7 @@ ! All elements of `mylist` argument must be named. i The indices of the unnamed elements are 1, 2, and 3 -# assert_named Test 52: error if no elements are named +# assert_named Test 50: error if no elements are named Code arg <- c(1, 2) @@ -299,7 +299,7 @@ ! All elements of `arg` argument must be named. i The indices of the unnamed elements are 1 and 2 -# assert_function Test 56: error if `arg` is not a function +# assert_function Test 51: error if `arg` is not a function Code example_fun(5) @@ -307,7 +307,7 @@ Error in `example_fun()`: ! Argument `arg` must be a function, but is a number. -# assert_function Test 59: error if `params` is missing with no default +# assert_function Test 54: error if `params` is missing with no default Code example_fun(sum) @@ -323,7 +323,7 @@ Error in `example_fun()`: ! "x" and "y" are not arguments of the function specified for `arg`. -# assert_unit Test 64: error if there are multiple units in the input dataset +# assert_unit Test 57: error if there are multiple units in the input dataset Code assert_unit(advs, param = "WEIGHT", required_unit = "kg", get_unit_expr = VSSTRESU) @@ -331,7 +331,7 @@ Error: ! Multiple units "kg" and "lb" found for "WEIGHT". Please review and update the units. -# assert_unit Test 65: error if unexpected unit in the input dataset +# assert_unit Test 58: error if unexpected unit in the input dataset Code assert_unit(advs, param = "WEIGHT", required_unit = "lb", get_unit_expr = VSSTRESU) @@ -339,7 +339,7 @@ Error: ! It is expected that "WEIGHT" has unit of "lb". In the input dataset the unit is "kg". -# assert_param_does_not_exist Test 66: error if parameter exists in the input dataset +# assert_param_does_not_exist Test 59: error if parameter exists in the input dataset Code assert_param_does_not_exist(advs, param = "WEIGHT") @@ -347,7 +347,7 @@ Error: ! The parameter code "WEIGHT" already exists in dataset `advs`. -# assert_varval_list Test 68: error if `arg` is not a list of var-value expressions +# assert_varval_list Test 61: error if `arg` is not a list of var-value expressions Code example_fun(c("USUBJID", "PARAMCD", "VISIT")) @@ -356,7 +356,7 @@ ! Argument `arg` must be a named list of expressions where each element is a symbol, character scalar, numeric scalar, an expression, or NA, but is a character vector. i To create a list of expressions use `exprs()`. -# assert_varval_list Test 69: error if `arg` is not a list of var-value expressions +# assert_varval_list Test 62: error if `arg` is not a list of var-value expressions Code example_fun(exprs(USUBJID, PARAMCD, NULL)) @@ -365,7 +365,7 @@ ! Argument `arg` must be a list of expressions where each element is a symbol, character scalar, numeric scalar, an expression, or NA, but is a list. i To create a list of expressions use `exprs()`. -# assert_varval_list Test 70: error if `required_elements` are missing from `arg` +# assert_varval_list Test 63: error if `required_elements` are missing from `arg` Code example_fun(exprs(DTHSEQ = AESEQ)) @@ -373,7 +373,7 @@ Error in `example_fun()`: ! The following required elements are missing from argument `arg`: "DTHDOM". -# assert_varval_list Test 72: error if `accept_expr` is TRUE and value is invalid +# assert_varval_list Test 65: error if `accept_expr` is TRUE and value is invalid Code example_fun(exprs(DTHSEQ = TRUE)) @@ -382,7 +382,7 @@ ! The elements of the list in argument `arg` must be a symbol, character scalar, numeric scalar, an expression, or NA. i "DTHSEQ" = `TRUE` is of type -# assert_varval_list Test 73: error if `accept_expr` is FALSE and value is invalid +# assert_varval_list Test 66: error if `accept_expr` is FALSE and value is invalid Code example_fun(exprs(DTHSEQ = exprs())) @@ -391,7 +391,7 @@ ! The elements of the list in argument `arg` must be a symbol, character scalar, numeric scalar, or NA. i "DTHSEQ" = `exprs()` is of type -# assert_list_element Test 82: error if the elements do not fulfill the condition +# assert_list_element Test 75: error if the elements do not fulfill the condition Code assert_list_element(list(list(var = expr(DTHDT), val = 1), list(var = expr( @@ -403,7 +403,7 @@ ! List element "val" must be `>=0` in argument `input`: i But, `input[[2]]$val = -1`, and `input[[3]]$val = -2` -# assert_one_to_one Test 83: error if there is a one to many mapping +# assert_one_to_one Test 76: error if there is a one to many mapping Code assert_one_to_one(dm, exprs(DOMAIN), exprs(USUBJID)) @@ -412,7 +412,7 @@ ! For some values of "DOMAIN" there is more than one value of "USUBJID" i Call `admiral::get_one_to_many_dataset()` to get all one-to-many values. -# assert_date_var Test 86: error if variable is not a date or datetime variable +# assert_date_var Test 79: error if variable is not a date or datetime variable Code example_fun(dataset = my_data, var = USUBJID) @@ -420,7 +420,7 @@ Error in `example_fun()`: ! Column "USUBJID" in dataset `dataset` must be a date or datetime, but is a character vector. -# assert_date_vector Test 90: error if `arg` is NULL and optional is FALSE +# assert_date_vector Test 83: error if `arg` is NULL and optional is FALSE Code example_fun(NULL) @@ -428,7 +428,7 @@ Error in `example_fun()`: ! Argument `arg` must be a date or datetime, but is NULL. -# assert_atomic_vector Test 91: error if input is not atomic vector +# assert_atomic_vector Test 84: error if input is not atomic vector Code assert_atomic_vector(x) @@ -436,7 +436,7 @@ Error: ! Argument `x` must be an atomic vector, but is a list. -# assert_same_type Test 93: error if different type +# assert_same_type Test 86: error if different type Code assert_same_type(true_value, false_value, missing_value) diff --git a/tests/testthat/test-assertions.R b/tests/testthat/test-assertions.R index 224f0053..d6ed0857 100644 --- a/tests/testthat/test-assertions.R +++ b/tests/testthat/test-assertions.R @@ -1,46 +1,6 @@ -# assert_has_variables ---- -## Test 1: error if a required variable is missing (deprecation error) ---- -test_that("assert_has_variables Test 1: error if a required variable is missing (deprecation error)", { # nolint - data <- dplyr::tribble( - ~USUBJID, - "1" - ) - - dm <- dplyr::tribble( - ~DOMAIN, ~USUBJID, - "DM", "01-701-1015", - "DM", "01-701-1016", - "DM", "01-701-1023", - "DM", "01-701-1024", - ) - - expect_error( - assert_has_variables(data, "TRT01P"), - class = "lifecycle_error_deprecated" - ) - - expect_error( - assert_has_variables(dm, c("TRT01P", "AVAL")), - class = "lifecycle_error_deprecated" - ) -}) - -## Test 2: no error if a required variable exists (deprecation error) ---- -test_that("assert_has_variables Test 2: no error if a required variable exists (deprecation error)", { # nolint - data <- dplyr::tribble( - ~USUBJID, - "1" - ) - - expect_error( - assert_has_variables(data, "USUBJID"), - class = "lifecycle_error_deprecated" - ) -}) - # assert_filter_cond ---- -## Test 3: `assert_filter_cond` works as expected ---- -test_that("assert_filter_cond Test 3: `assert_filter_cond` works as expected", { +## Test 1: `assert_filter_cond` works as expected ---- +test_that("assert_filter_cond Test 1: `assert_filter_cond` works as expected", { fc <- expr(AGE == 64) expect_identical( assert_filter_cond(fc), @@ -71,8 +31,8 @@ test_that("assert_filter_cond Test 3: `assert_filter_cond` works as expected", { }) # assert_data_frame ---- -## Test 4: error if not a dataframe ---- -test_that("assert_data_frame Test 4: error if not a dataframe", { +## Test 2: error if not a dataframe ---- +test_that("assert_data_frame Test 2: error if not a dataframe", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -86,8 +46,8 @@ test_that("assert_data_frame Test 4: error if not a dataframe", { ) }) -## Test 5: assert_data_frame extract_vars() works as intended ---- -test_that("assert_data_frame Test 5: assert_data_frame extract_vars() works as intended", { +## Test 3: assert_data_frame extract_vars() works as intended ---- +test_that("assert_data_frame Test 3: assert_data_frame extract_vars() works as intended", { input <- dplyr::tribble( ~STUDYID, ~USUBJID, ~SEQ, "A", "1", 1, @@ -105,8 +65,8 @@ test_that("assert_data_frame Test 5: assert_data_frame extract_vars() works as i expect_invisible(example_fun(input, order = exprs(SEQ))) }) -## Test 6: assert_data_frame works if extract_vars() has NULL input ---- -test_that("assert_data_frame Test 6: assert_data_frame works if extract_vars() has NULL input", { +## Test 4: assert_data_frame works if extract_vars() has NULL input ---- +test_that("assert_data_frame Test 4: assert_data_frame works if extract_vars() has NULL input", { input <- dplyr::tribble( ~STUDYID, ~USUBJID, ~SEQ, "A", "1", 1, @@ -124,8 +84,8 @@ test_that("assert_data_frame Test 6: assert_data_frame works if extract_vars() h expect_invisible(example_fun(input)) }) -## Test 7: error if dataframe is grouped ---- -test_that("assert_data_frame Test 7: error if dataframe is grouped", { +## Test 5: error if dataframe is grouped ---- +test_that("assert_data_frame Test 5: error if dataframe is grouped", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -147,8 +107,8 @@ test_that("assert_data_frame Test 7: error if dataframe is grouped", { ) }) -## Test 8: error if an expected variable is missing ---- -test_that("assert_data_frame Test 8: error if an expected variable is missing", { +## Test 6: error if an expected variable is missing ---- +test_that("assert_data_frame Test 6: error if an expected variable is missing", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -169,8 +129,8 @@ test_that("assert_data_frame Test 8: error if an expected variable is missing", ) }) -## Test 9: error if expected variables are missing ---- -test_that("assert_data_frame Test 9: error if expected variables are missing", { +## Test 7: error if expected variables are missing ---- +test_that("assert_data_frame Test 7: error if expected variables are missing", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -191,8 +151,8 @@ test_that("assert_data_frame Test 9: error if expected variables are missing", { ) }) -## Test 10: no error if optional is TRUE and `arg` is NULL ---- -test_that("assert_data_frame Test 10: no error if optional is TRUE and `arg` is NULL", { +## Test 8: no error if optional is TRUE and `arg` is NULL ---- +test_that("assert_data_frame Test 8: no error if optional is TRUE and `arg` is NULL", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID), optional = TRUE) } @@ -202,8 +162,8 @@ test_that("assert_data_frame Test 10: no error if optional is TRUE and `arg` is ) }) -## Test 11: error if required variables are missing ---- -test_that("assert_data_frame Test 11: error if required variables are missing", { +## Test 9: error if required variables are missing ---- +test_that("assert_data_frame Test 9: error if required variables are missing", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -219,8 +179,8 @@ test_that("assert_data_frame Test 11: error if required variables are missing", ) }) -## Test 12: error if required variable is missing ---- -test_that("assert_data_frame Test 12: error if required variable is missing", { +## Test 10: error if required variable is missing ---- +test_that("assert_data_frame Test 10: error if required variable is missing", { example_fun <- function(dataset) { assert_data_frame(dataset, required_vars = exprs(STUDYID, USUBJID)) } @@ -237,8 +197,8 @@ test_that("assert_data_frame Test 12: error if required variable is missing", { }) # assert_character_scalar ---- -## Test 13: no error if optional is TRUE and `arg` is NULL ---- -test_that("assert_character_scalar Test 13: no error if optional is TRUE and `arg` is NULL", { +## Test 11: no error if optional is TRUE and `arg` is NULL ---- +test_that("assert_character_scalar Test 11: no error if optional is TRUE and `arg` is NULL", { example_fun <- function(character) { assert_character_scalar(character, optional = TRUE) } @@ -248,8 +208,8 @@ test_that("assert_character_scalar Test 13: no error if optional is TRUE and `ar ) }) -## Test 14: no error, case_sensitive = FALSE ---- -test_that("assert_character_scalar Test 14: no error, case_sensitive = FALSE", { +## Test 12: no error, case_sensitive = FALSE ---- +test_that("assert_character_scalar Test 12: no error, case_sensitive = FALSE", { example_fun <- function(character) { assert_character_scalar(character, values = c("test"), case_sensitive = FALSE) } @@ -286,8 +246,8 @@ test_that("assert_character_scalar Test 14: no error, case_sensitive = FALSE", { expect_equal(out, "months") }) -## Test 15: error if `arg` not in values ---- -test_that("assert_character_scalar Test 15: error if `arg` not in values", { +## Test 13: error if `arg` not in values ---- +test_that("assert_character_scalar Test 13: error if `arg` not in values", { check_unit <- function(duration_unit) { assert_character_scalar( duration_unit, @@ -318,8 +278,8 @@ test_that("assert_character_scalar Test 15: error if `arg` not in values", { expect_snapshot(check_unit2("month"), error = TRUE) }) -## Test 16: error if not character ---- -test_that("assert_character_scalar Test 16: error if not character", { +## Test 14: error if not character ---- +test_that("assert_character_scalar Test 14: error if not character", { example_fun2 <- function(msg_type) { msg_type <- assert_character_scalar(msg_type, values = c("warning", "error"), case_sensitive = FALSE @@ -340,8 +300,8 @@ test_that("assert_character_scalar Test 16: error if not character", { ) }) -## Test 17: error if input is a vector ---- -test_that("assert_character_scalar Test 17: error if input is a vector", { +## Test 15: error if input is a vector ---- +test_that("assert_character_scalar Test 15: error if input is a vector", { example_fun2 <- function(msg_type) { msg_type <- assert_character_scalar(msg_type, values = c("warning", "error"), case_sensitive = FALSE @@ -363,8 +323,8 @@ test_that("assert_character_scalar Test 17: error if input is a vector", { }) # assert_character_vector ---- -## Test 18: error if `arg` not a character vector ---- -test_that("assert_character_vector Test 18: error if `arg` not a character vector", { +## Test 16: error if `arg` not a character vector ---- +test_that("assert_character_vector Test 16: error if `arg` not a character vector", { arg <- c(1, 2, 3) expect_error( @@ -378,8 +338,8 @@ test_that("assert_character_vector Test 18: error if `arg` not a character vecto ) }) -## Test 19: error if `arg` is not in values ---- -test_that("assert_character_vector Test 19: error if `arg` is not in values", { +## Test 17: error if `arg` is not in values ---- +test_that("assert_character_vector Test 17: error if `arg` is not in values", { example_fun <- function(character) { assert_character_vector(character, values = c("test", "oak")) } @@ -394,8 +354,8 @@ test_that("assert_character_vector Test 19: error if `arg` is not in values", { ) }) -## Test 20: arg_name correctly displayed in name check ---- -test_that("assert_character_vector Test 20: arg_name correctly displayed in name check", { +## Test 18: arg_name correctly displayed in name check ---- +test_that("assert_character_vector Test 18: arg_name correctly displayed in name check", { example_fun <- function(character) { assert_character_vector(character, values = c("test", "oak"), named = TRUE) } @@ -411,8 +371,8 @@ test_that("assert_character_vector Test 20: arg_name correctly displayed in name }) # assert_logical_scalar ---- -## Test 21: no error if optional is TRUE and `arg` is NULL ---- -test_that("assert_logical_scalar Test 21: no error if optional is TRUE and `arg` is NULL", { +## Test 19: no error if optional is TRUE and `arg` is NULL ---- +test_that("assert_logical_scalar Test 19: no error if optional is TRUE and `arg` is NULL", { example_fun <- function(arg) { assert_logical_scalar(arg, optional = TRUE) } @@ -422,8 +382,8 @@ test_that("assert_logical_scalar Test 21: no error if optional is TRUE and `arg` ) }) -## Test 22: error if `arg` is not TRUE or FALSE ---- -test_that("assert_logical_scalar Test 22: error if `arg` is not TRUE or FALSE", { +## Test 20: error if `arg` is not TRUE or FALSE ---- +test_that("assert_logical_scalar Test 20: error if `arg` is not TRUE or FALSE", { example_fun <- function(arg) { assert_logical_scalar(arg) } @@ -438,8 +398,8 @@ test_that("assert_logical_scalar Test 22: error if `arg` is not TRUE or FALSE", }) # assert_symbol ---- -## Test 23: no error if optional = TRUE and `arg` = NULL ---- -test_that("assert_symbol Test 23: no error if optional = TRUE and `arg` = NULL", { +## Test 21: no error if optional = TRUE and `arg` = NULL ---- +test_that("assert_symbol Test 21: no error if optional = TRUE and `arg` = NULL", { f <- function(var) { v <- enexpr(var) } @@ -455,8 +415,8 @@ test_that("assert_symbol Test 23: no error if optional = TRUE and `arg` = NULL", ) }) -## Test 24: `assert_symbol` throws an error if `arg` is missing ---- -test_that("assert_symbol Test 24: `assert_symbol` throws an error if `arg` is missing", { +## Test 22: `assert_symbol` throws an error if `arg` is missing ---- +test_that("assert_symbol Test 22: `assert_symbol` throws an error if `arg` is missing", { f <- function(var) { v <- enexpr(var) } @@ -472,8 +432,8 @@ test_that("assert_symbol Test 24: `assert_symbol` throws an error if `arg` is mi expect_snapshot(example_fun(f()), error = TRUE) }) -## Test 25: `assert_symbol` throws an error if `arg` is not a symbol ---- -test_that("assert_symbol Test 25: `assert_symbol` throws an error if `arg` is not a symbol", { +## Test 23: `assert_symbol` throws an error if `arg` is not a symbol ---- +test_that("assert_symbol Test 23: `assert_symbol` throws an error if `arg` is not a symbol", { f <- function(var) { v <- enexpr(var) } @@ -489,8 +449,8 @@ test_that("assert_symbol Test 25: `assert_symbol` throws an error if `arg` is no expect_snapshot(example_fun(f(NULL)), error = TRUE) }) -## Test 26: `assert_symbol` does not throw an error if `arg` is a symbol ---- -test_that("assert_symbol Test 26: `assert_symbol` does not throw an error if `arg` is a symbol", { +## Test 24: `assert_symbol` does not throw an error if `arg` is a symbol ---- +test_that("assert_symbol Test 24: `assert_symbol` does not throw an error if `arg` is a symbol", { f <- function(var) { v <- enexpr(var) } @@ -513,8 +473,8 @@ test_that("assert_symbol Test 26: `assert_symbol` does not throw an error if `ar }) # assert_expr ---- -## Test 27: `assert_expr` does not throw an error if `arg` is an expression ---- -test_that("assert_expr Test 27: `assert_expr` does not throw an error if `arg` is an expression", { +## Test 25: `assert_expr` does not throw an error if `arg` is an expression ---- +test_that("assert_expr Test 25: `assert_expr` does not throw an error if `arg` is an expression", { dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", @@ -526,15 +486,15 @@ test_that("assert_expr Test 27: `assert_expr` does not throw an error if `arg` i ) }) -## Test 28: no error if optional is TRUE and `arg` is NULL ---- -test_that("assert_expr Test 28: no error if optional is TRUE and `arg` is NULL", { +## Test 26: no error if optional is TRUE and `arg` is NULL ---- +test_that("assert_expr Test 26: no error if optional is TRUE and `arg` is NULL", { expect_invisible( assert_expr(var <- NULL, optional = TRUE) ) }) -## Test 29: `assert_expr` throws an error if `arg` is missing ---- -test_that("assert_expr Test 29: `assert_expr` throws an error if `arg` is missing", { +## Test 27: `assert_expr` throws an error if `arg` is missing ---- +test_that("assert_expr Test 27: `assert_expr` throws an error if `arg` is missing", { expect_error( assert_expr(), class = "assert_expr" @@ -554,8 +514,8 @@ test_that("assert_expr Test 29: `assert_expr` throws an error if `arg` is missin ) }) -## Test 30: `assert_expr` throws an error if `arg` is not an expression ---- -test_that("assert_expr Test 30: `assert_expr` throws an error if `arg` is not an expression", { +## Test 28: `assert_expr` throws an error if `arg` is not an expression ---- +test_that("assert_expr Test 28: `assert_expr` throws an error if `arg` is not an expression", { expect_error( { var <- c(1, 2) @@ -574,8 +534,8 @@ test_that("assert_expr Test 30: `assert_expr` throws an error if `arg` is not an }) # assert_vars ---- -## Test 31: no error if expected input ---- -test_that("assert_vars Test 31: no error if expected input", { +## Test 29: no error if expected input ---- +test_that("assert_vars Test 29: no error if expected input", { expect_invisible(assert_vars(exprs(USUBJID, PARAMCD))) expect_invisible(assert_vars( exprs(APERSDT = APxxSDT, APEREDT = APxxEDT), @@ -583,8 +543,8 @@ test_that("assert_vars Test 31: no error if expected input", { )) }) -## Test 32: error if unexpected input ---- -test_that("assert_vars Test 32: error if unexpected input", { +## Test 30: error if unexpected input ---- +test_that("assert_vars Test 30: error if unexpected input", { expect_error( assert_vars(AVAL + 1), class = "assert_vars" @@ -636,8 +596,8 @@ test_that("assert_vars Test 32: error if unexpected input", { ) }) -## Test 33: error if some elements of `arg` are not unquoted variable names ---- -test_that("assert_vars Test 33: error if some elements of `arg` are not unquoted variable names", { +## Test 31: error if some elements of `arg` are not unquoted variable names ---- +test_that("assert_vars Test 31: error if some elements of `arg` are not unquoted variable names", { example_fun <- function(arg) { assert_vars(arg) } @@ -654,8 +614,8 @@ test_that("assert_vars Test 33: error if some elements of `arg` are not unquoted }) # assert_integer_scalar ---- -## Test 34: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_integer_scalar Test 34: no error if `arg` is NULL and optional is TRUE", { +## Test 32: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_integer_scalar Test 32: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_integer_scalar(arg, optional = TRUE) } @@ -665,8 +625,8 @@ test_that("assert_integer_scalar Test 34: no error if `arg` is NULL and optional ) }) -## Test 35: error if chosen subset not in subsets ---- -test_that("assert_integer_scalar Test 35: error if chosen subset not in subsets", { +## Test 33: error if chosen subset not in subsets ---- +test_that("assert_integer_scalar Test 33: error if chosen subset not in subsets", { example_fun <- function(arg) { assert_integer_scalar(arg, subset = "infinity") } @@ -682,8 +642,8 @@ test_that("assert_integer_scalar Test 35: error if chosen subset not in subsets" ) }) -## Test 36: no error if `arg` is in selected subset ---- -test_that("assert_integer_scalar Test 36: no error if `arg` is in selected subset", { +## Test 34: no error if `arg` is in selected subset ---- +test_that("assert_integer_scalar Test 34: no error if `arg` is in selected subset", { example_fun <- function(arg) { assert_integer_scalar(arg, subset = "positive") } @@ -693,8 +653,8 @@ test_that("assert_integer_scalar Test 36: no error if `arg` is in selected subse ) }) -## Test 37: error if `arg` is not an integer scalar ---- -test_that("assert_integer_scalar Test 37: error if `arg` is not an integer scalar", { +## Test 35: error if `arg` is not an integer scalar ---- +test_that("assert_integer_scalar Test 35: error if `arg` is not an integer scalar", { example_fun <- function(arg) { assert_integer_scalar(arg) } @@ -725,8 +685,8 @@ test_that("assert_integer_scalar Test 37: error if `arg` is not an integer scala }) # assert_numeric_vector ---- -## Test 38: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_numeric_vector Test 38: no error if `arg` is NULL and optional is TRUE", { +## Test 36: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_numeric_vector Test 36: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_numeric_vector(arg, optional = TRUE) } @@ -736,8 +696,8 @@ test_that("assert_numeric_vector Test 38: no error if `arg` is NULL and optional ) }) -## Test 39: error if `arg` is not a numeric vector ---- -test_that("assert_numeric_vector Test 39: error if `arg` is not a numeric vector", { +## Test 37: error if `arg` is not a numeric vector ---- +test_that("assert_numeric_vector Test 37: error if `arg` is not a numeric vector", { example_fun <- function(arg) { assert_numeric_vector(arg) } @@ -773,8 +733,8 @@ test_that("assert_numeric_vector Test 39: error if `arg` is not a numeric vector }) # assert_s3_class ---- -## Test 40: error if `arg` is not an object of a specific class S3 ---- -test_that("assert_s3_class Test 40: error if `arg` is not an object of a specific class S3", { +## Test 38: error if `arg` is not an object of a specific class S3 ---- +test_that("assert_s3_class Test 38: error if `arg` is not an object of a specific class S3", { example_fun <- function(arg) { assert_s3_class(arg, "factor") } @@ -789,8 +749,8 @@ test_that("assert_s3_class Test 40: error if `arg` is not an object of a specifi ) }) -## Test 41: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_s3_class Test 41: no error if `arg` is NULL and optional is TRUE", { +## Test 39: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_s3_class Test 39: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_s3_class(arg, cls = "factor", optional = TRUE) } @@ -800,8 +760,8 @@ test_that("assert_s3_class Test 41: no error if `arg` is NULL and optional is TR ) }) -## Test 42: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_s3_class Test 42: error if `arg` is NULL and optional is FALSE", { +## Test 40: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_s3_class Test 40: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_s3_class(arg, cls = "factor", optional = FALSE) } @@ -813,8 +773,8 @@ test_that("assert_s3_class Test 42: error if `arg` is NULL and optional is FALSE expect_snapshot(example_fun(NULL), error = TRUE) }) -## Test 43: no error if `arg` is an object of a specific class S3 ---- -test_that("assert_s3_class Test 43: no error if `arg` is an object of a specific class S3", { +## Test 41: no error if `arg` is an object of a specific class S3 ---- +test_that("assert_s3_class Test 41: no error if `arg` is an object of a specific class S3", { example_fun <- function(arg) { assert_s3_class(arg, "factor") } @@ -823,8 +783,8 @@ test_that("assert_s3_class Test 43: no error if `arg` is an object of a specific }) # assert_list_of ---- -## Test 44: error if `arg` is not a list of specific class S3 objects ---- -test_that("assert_list_of Test 44: error if `arg` is not a list of specific class S3 objects", { +## Test 42: error if `arg` is not a list of specific class S3 objects ---- +test_that("assert_list_of Test 42: error if `arg` is not a list of specific class S3 objects", { example_fun <- function(arg) { assert_list_of(arg, "factor") } @@ -839,8 +799,8 @@ test_that("assert_list_of Test 44: error if `arg` is not a list of specific clas ) }) -## Test 45: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_list_of Test 45: no error if `arg` is NULL and optional is TRUE", { +## Test 43: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_list_of Test 43: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_list_of(arg, cls = "factor", optional = TRUE) } @@ -850,8 +810,8 @@ test_that("assert_list_of Test 45: no error if `arg` is NULL and optional is TRU ) }) -## Test 46: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_list_of Test 46: error if `arg` is NULL and optional is FALSE", { +## Test 44: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_list_of Test 44: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_list_of(arg, cls = "factor", optional = FALSE) } @@ -863,8 +823,8 @@ test_that("assert_list_of Test 46: error if `arg` is NULL and optional is FALSE" expect_snapshot(example_fun(NULL), error = TRUE) }) -## Test 47: no error if `arg` is a list of specific class S3 objects ---- -test_that("assert_list_of Test 47: no error if `arg` is a list of specific class S3 objects", { +## Test 45: no error if `arg` is a list of specific class S3 objects ---- +test_that("assert_list_of Test 45: no error if `arg` is a list of specific class S3 objects", { example_fun <- function(arg) { assert_list_of(arg, "factor") } @@ -876,8 +836,8 @@ test_that("assert_list_of Test 47: no error if `arg` is a list of specific class ) }) -## Test 48: error if `arg` is not a named list (no elements named) ---- -test_that("assert_list_of Test 48: error if `arg` is not a named list (no elements named)", { +## Test 46: error if `arg` is not a named list (no elements named) ---- +test_that("assert_list_of Test 46: error if `arg` is not a named list (no elements named)", { expect_error( { mylist <- list(1, 2, 3) @@ -894,8 +854,8 @@ test_that("assert_list_of Test 48: error if `arg` is not a named list (no elemen ) }) -## Test 49: error if `arg` is not a named list (some elements named) ---- -test_that("assert_list_of Test 49: error if `arg` is not a named list (some elements named)", { +## Test 47: error if `arg` is not a named list (some elements named) ---- +test_that("assert_list_of Test 47: error if `arg` is not a named list (some elements named)", { expect_error( { mylist <- list(1, 2, 3, d = 4) @@ -912,21 +872,21 @@ test_that("assert_list_of Test 49: error if `arg` is not a named list (some elem ) }) -## Test 50: no error if `arg` is a named list ---- -test_that("assert_list_of Test 50: no error if `arg` is a named list", { +## Test 48: no error if `arg` is a named list ---- +test_that("assert_list_of Test 48: no error if `arg` is a named list", { expect_invisible( assert_list_of(mylist <- list(a = 1, b = 2, c = 3), cls = "numeric", named = TRUE) ) }) # assert_named ---- -## Test 51: no error if arg is NULL and optional = TRUE ---- -test_that("assert_named Test 51: no error if arg is NULL and optional = TRUE", { +## Test 49: no error if arg is NULL and optional = TRUE ---- +test_that("assert_named Test 49: no error if arg is NULL and optional = TRUE", { expect_invisible(assert_named(arg <- NULL, optional = TRUE)) }) -## Test 52: error if no elements are named ---- -test_that("assert_named Test 52: error if no elements are named", { +## Test 50: error if no elements are named ---- +test_that("assert_named Test 50: error if no elements are named", { expect_error( { arg <- c(1, 2) @@ -944,66 +904,9 @@ test_that("assert_named Test 52: error if no elements are named", { ) }) -# assert_named_exprs ---- -## Test 53: error if `arg` is not a named list of expressions (deprecation error) ---- -test_that("assert_named_exprs Test 53: error if `arg` is not a named list of expressions (deprecation error)", { # nolint - example_fun <- function(arg) { - assert_named_exprs(arg) - } - - arg <- list("test") - names(arg) <- c("") - - expect_error( - example_fun(5), - class = "lifecycle_error_deprecated" - ) - dm <- dplyr::tribble( - ~DOMAIN, ~USUBJID, - "DM", "01-701-1015", - "DM", "01-701-1016", - ) - expect_error( - example_fun(dm), - class = "lifecycle_error_deprecated" - ) - expect_error( - example_fun(list(1, 2, TRUE)), - class = "lifecycle_error_deprecated" - ) - expect_error( - example_fun(arg), - class = "lifecycle_error_deprecated" - ) -}) - -## Test 54: no error if `arg` is NULL and optional is TRUE (deprecation error) ---- -test_that("assert_named_exprs Test 54: no error if `arg` is NULL and optional is TRUE (deprecation error)", { # nolint - example_fun <- function(arg) { - assert_named_exprs(arg, optional = TRUE) - } - - expect_error( - example_fun(NULL), - class = "lifecycle_error_deprecated" - ) -}) - -## Test 55: no error if `arg` is a named list of expressions (deprecation error) ---- -test_that("assert_named_exprs Test 55: no error if `arg` is a named list of expressions (deprecation error)", { # nolint - example_fun <- function(arg) { - assert_named_exprs(arg) - } - - expect_error( - example_fun(rlang::exprs()), - class = "lifecycle_error_deprecated" - ) -}) - # assert_function ---- -## Test 56: error if `arg` is not a function ---- -test_that("assert_function Test 56: error if `arg` is not a function", { +## Test 51: error if `arg` is not a function ---- +test_that("assert_function Test 51: error if `arg` is not a function", { example_fun <- function(arg) { assert_function(arg) } @@ -1016,8 +919,8 @@ test_that("assert_function Test 56: error if `arg` is not a function", { expect_error(example_fun(), class = "assert_function") }) -## Test 57: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_function Test 57: no error if `arg` is NULL and optional is TRUE", { +## Test 52: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_function Test 52: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_function(arg, optional = TRUE) } @@ -1027,8 +930,8 @@ test_that("assert_function Test 57: no error if `arg` is NULL and optional is TR ) }) -## Test 58: no error if `arg` is a function with all parameters defined ---- -test_that("assert_function Test 58: no error if `arg` is a function with all parameters defined", { +## Test 53: no error if `arg` is a function with all parameters defined ---- +test_that("assert_function Test 53: no error if `arg` is a function with all parameters defined", { example_fun <- function(arg) { assert_function(arg, params = c("x")) } @@ -1036,8 +939,8 @@ test_that("assert_function Test 58: no error if `arg` is a function with all par expect_invisible(example_fun(mean)) }) -## Test 59: error if `params` is missing with no default ---- -test_that("assert_function Test 59: error if `params` is missing with no default", { +## Test 54: error if `params` is missing with no default ---- +test_that("assert_function Test 54: error if `params` is missing with no default", { example_fun <- function(arg) { assert_function(arg, params = c("x")) } @@ -1065,49 +968,17 @@ test_that("assert_function Test 59: error if `params` is missing with no defau ) }) -## Test 60: If dot-dot-dot is a argument ---- -test_that("assert_function Test 60: If dot-dot-dot is a argument", { +## Test 55: If dot-dot-dot is a argument ---- +test_that("assert_function Test 55: If dot-dot-dot is a argument", { example_fun <- function(derivation, args = NULL) { assert_function(derivation, names(args)) } expect_invisible(example_fun(mutate, args = exprs(AVAL = x + 1))) }) - - -# assert_function_param ---- -## Test 61: no error if `arg` is a parameter of a function (deprecation error) ---- -test_that("assert_function_param Test 61: no error if `arg` is a parameter of a function (deprecation error)", { # nolint - hello <- function(name) { - print(sprintf("Hello %s", name)) - } - - expect_error( - assert_function_param("hello", params = "name"), - class = "lifecycle_error_deprecated" - ) -}) - -## Test 62: error if expected function parameters are missing (deprecation error) ---- -test_that("assert_function_param Test 62: error if expected function parameters are missing (deprecation error)", { # nolint - hello <- function(name) { - print(sprintf("Hello %s", name)) - } - - expect_error( - assert_function_param("hello", "surname"), - class = "lifecycle_error_deprecated" - ) - - expect_error( - assert_function_param("hello", params = c("surname", "firstname")), - class = "lifecycle_error_deprecated" - ) -}) - # assert_unit ---- -## Test 63: no error if the parameter is provided in the expected unit ---- -test_that("assert_unit Test 63: no error if the parameter is provided in the expected unit", { +## Test 56: no error if the parameter is provided in the expected unit ---- +test_that("assert_unit Test 56: no error if the parameter is provided in the expected unit", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1119,8 +990,8 @@ test_that("assert_unit Test 63: no error if the parameter is provided in the exp ) }) -## Test 64: error if there are multiple units in the input dataset ---- -test_that("assert_unit Test 64: error if there are multiple units in the input dataset", { +## Test 57: error if there are multiple units in the input dataset ---- +test_that("assert_unit Test 57: error if there are multiple units in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1137,8 +1008,8 @@ test_that("assert_unit Test 64: error if there are multiple units in the input d ) }) -## Test 65: error if unexpected unit in the input dataset ---- -test_that("assert_unit Test 65: error if unexpected unit in the input dataset", { +## Test 58: error if unexpected unit in the input dataset ---- +test_that("assert_unit Test 58: error if unexpected unit in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1156,8 +1027,8 @@ test_that("assert_unit Test 65: error if unexpected unit in the input dataset", }) # assert_param_does_not_exist ---- -## Test 66: error if parameter exists in the input dataset ---- -test_that("assert_param_does_not_exist Test 66: error if parameter exists in the input dataset", { +## Test 59: error if parameter exists in the input dataset ---- +test_that("assert_param_does_not_exist Test 59: error if parameter exists in the input dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1175,8 +1046,8 @@ test_that("assert_param_does_not_exist Test 66: error if parameter exists in the ) }) -## Test 67: no error if the parameter exists in the dataset ---- -test_that("assert_param_does_not_exist Test 67: no error if the parameter exists in the dataset", { +## Test 60: no error if the parameter exists in the dataset ---- +test_that("assert_param_does_not_exist Test 60: no error if the parameter exists in the dataset", { advs <- dplyr::tribble( ~USUBJID, ~VSTESTCD, ~VSTRESN, ~VSSTRESU, ~PARAMCD, ~AVAL, "P01", "WEIGHT", 80.1, "kg", "WEIGHT", 80.1, @@ -1189,8 +1060,8 @@ test_that("assert_param_does_not_exist Test 67: no error if the parameter exists }) # assert_varval_list ---- -## Test 68: error if `arg` is not a list of var-value expressions ---- -test_that("assert_varval_list Test 68: error if `arg` is not a list of var-value expressions", { +## Test 61: error if `arg` is not a list of var-value expressions ---- +test_that("assert_varval_list Test 61: error if `arg` is not a list of var-value expressions", { example_fun <- function(arg) { assert_varval_list(arg, accept_var = FALSE) } @@ -1205,8 +1076,8 @@ test_that("assert_varval_list Test 68: error if `arg` is not a list of var-value ) }) -## Test 69: error if `arg` is not a list of var-value expressions ---- -test_that("assert_varval_list Test 69: error if `arg` is not a list of var-value expressions", { +## Test 62: error if `arg` is not a list of var-value expressions ---- +test_that("assert_varval_list Test 62: error if `arg` is not a list of var-value expressions", { example_fun <- function(arg) { assert_varval_list(arg, accept_var = TRUE) } @@ -1221,8 +1092,8 @@ test_that("assert_varval_list Test 69: error if `arg` is not a list of var-value ) }) -## Test 70: error if `required_elements` are missing from `arg` ---- -test_that("assert_varval_list Test 70: error if `required_elements` are missing from `arg`", { +## Test 63: error if `required_elements` are missing from `arg` ---- +test_that("assert_varval_list Test 63: error if `required_elements` are missing from `arg`", { example_fun <- function(arg) { assert_varval_list(arg, required_elements = "DTHDOM") } @@ -1237,8 +1108,8 @@ test_that("assert_varval_list Test 70: error if `required_elements` are missing ) }) -## Test 71: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_varval_list Test 71: no error if `arg` is NULL and optional is TRUE", { +## Test 64: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_varval_list Test 64: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_varval_list(arg, optional = TRUE) } @@ -1248,8 +1119,8 @@ test_that("assert_varval_list Test 71: no error if `arg` is NULL and optional is ) }) -## Test 72: error if `accept_expr` is TRUE and value is invalid ---- -test_that("assert_varval_list Test 72: error if `accept_expr` is TRUE and value is invalid", { +## Test 65: error if `accept_expr` is TRUE and value is invalid ---- +test_that("assert_varval_list Test 65: error if `accept_expr` is TRUE and value is invalid", { example_fun <- function(arg) { assert_varval_list(arg, accept_expr = TRUE) } @@ -1264,8 +1135,8 @@ test_that("assert_varval_list Test 72: error if `accept_expr` is TRUE and value ) }) -## Test 73: error if `accept_expr` is FALSE and value is invalid ---- -test_that("assert_varval_list Test 73: error if `accept_expr` is FALSE and value is invalid", { +## Test 66: error if `accept_expr` is FALSE and value is invalid ---- +test_that("assert_varval_list Test 66: error if `accept_expr` is FALSE and value is invalid", { example_fun <- function(arg) { assert_varval_list(arg, accept_expr = FALSE) } @@ -1280,8 +1151,8 @@ test_that("assert_varval_list Test 73: error if `accept_expr` is FALSE and value ) }) -## Test 74: no error if an argument is a variable-value list ---- -test_that("assert_varval_list Test 74: no error if an argument is a variable-value list", { +## Test 67: no error if an argument is a variable-value list ---- +test_that("assert_varval_list Test 67: no error if an argument is a variable-value list", { example_fun <- function(arg) { assert_varval_list(arg) } @@ -1292,24 +1163,24 @@ test_that("assert_varval_list Test 74: no error if an argument is a variable-val }) # assert_expr_list ---- -## Test 75: error if `arg` is not a list of expressions ---- -test_that("assert_expr_list Test 75: error if `arg` is not a list of expressions", { +## Test 68: error if `arg` is not a list of expressions ---- +test_that("assert_expr_list Test 68: error if `arg` is not a list of expressions", { expect_error( assert_expr_list(arg <- c("USUBJID", "PARAMCD", "VISIT")), class = "assert_expr_list" ) }) -## Test 76: error if `arg` is not a named list of expressions ---- -test_that("assert_expr_list Test 76: error if `arg` is not a named list of expressions", { +## Test 69: error if `arg` is not a named list of expressions ---- +test_that("assert_expr_list Test 69: error if `arg` is not a named list of expressions", { expect_error( assert_expr_list(arg <- exprs(USUBJID, PARAMCD, NULL), named = TRUE), regexp = "argument must be named" ) }) -## Test 77: error if `required_elements` are missing from `arg` ---- -test_that("assert_expr_list Test 77: error if `required_elements` are missing from `arg`", { +## Test 70: error if `required_elements` are missing from `arg` ---- +test_that("assert_expr_list Test 70: error if `required_elements` are missing from `arg`", { expect_error( assert_expr_list( arg <- exprs(DTHSEQ = AESEQ), @@ -1319,23 +1190,23 @@ test_that("assert_expr_list Test 77: error if `required_elements` are missing fr ) }) -## Test 78: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_expr_list Test 78: no error if `arg` is NULL and optional is TRUE", { +## Test 71: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_expr_list Test 71: no error if `arg` is NULL and optional is TRUE", { expect_invisible( assert_expr_list(NULL, optional = TRUE) ) }) -## Test 79: error if element is invalid ---- -test_that("assert_expr_list Test 79: error if element is invalid", { +## Test 72: error if element is invalid ---- +test_that("assert_expr_list Test 72: error if element is invalid", { expect_error( assert_expr_list(arg <- exprs(DTHSEQ = !!mean)), class = "assert_expr_list" ) }) -## Test 80: no error if argument is valid ---- -test_that("assert_expr_list Test 80: no error if argument is valid", { +## Test 73: no error if argument is valid ---- +test_that("assert_expr_list Test 73: no error if argument is valid", { expect_invisible( assert_expr_list(arg <- exprs( DTHDOM = "AE", @@ -1346,8 +1217,8 @@ test_that("assert_expr_list Test 80: no error if argument is valid", { }) # assert_list_element ---- -## Test 81: no error if the elements fulfill a certain condition ---- -test_that("assert_list_element Test 81: no error if the elements fulfill a certain condition", { +## Test 74: no error if the elements fulfill a certain condition ---- +test_that("assert_list_element Test 74: no error if the elements fulfill a certain condition", { expect_invisible( assert_list_element( list( @@ -1361,8 +1232,8 @@ test_that("assert_list_element Test 81: no error if the elements fulfill a certa ) }) -## Test 82: error if the elements do not fulfill the condition ---- -test_that("assert_list_element Test 82: error if the elements do not fulfill the condition", { +## Test 75: error if the elements do not fulfill the condition ---- +test_that("assert_list_element Test 75: error if the elements do not fulfill the condition", { expect_error( assert_list_element( list( @@ -1393,8 +1264,8 @@ test_that("assert_list_element Test 82: error if the elements do not fulfill the }) # assert_one_to_one ---- -## Test 83: error if there is a one to many mapping ---- -test_that("assert_one_to_one Test 83: error if there is a one to many mapping", { +## Test 76: error if there is a one to many mapping ---- +test_that("assert_one_to_one Test 76: error if there is a one to many mapping", { dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", @@ -1416,8 +1287,8 @@ test_that("assert_one_to_one Test 83: error if there is a one to many mapping", admiraldev_environment$one_to_many <- NULL }) -## Test 84: error if there is a many to one mapping ---- -test_that("assert_one_to_one Test 84: error if there is a many to one mapping", { +## Test 77: error if there is a many to one mapping ---- +test_that("assert_one_to_one Test 77: error if there is a many to one mapping", { dm <- dplyr::tribble( ~DOMAIN, ~USUBJID, "DM", "01-701-1015", @@ -1433,8 +1304,8 @@ test_that("assert_one_to_one Test 84: error if there is a many to one mapping", admiraldev_environment$many_to_one <- NULL }) -## Test 85: dataset is returned invisible if one-to-one ---- -test_that("assert_one_to_one Test 85: dataset is returned invisible if one-to-one", { +## Test 78: dataset is returned invisible if one-to-one ---- +test_that("assert_one_to_one Test 78: dataset is returned invisible if one-to-one", { df <- dplyr::tribble( ~SPECIES, ~SPECIESN, "DOG", 1L, @@ -1450,8 +1321,8 @@ test_that("assert_one_to_one Test 85: dataset is returned invisible if one-to-on }) # assert_date_var ---- -## Test 86: error if variable is not a date or datetime variable ---- -test_that("assert_date_var Test 86: error if variable is not a date or datetime variable", { +## Test 79: error if variable is not a date or datetime variable ---- +test_that("assert_date_var Test 79: error if variable is not a date or datetime variable", { example_fun <- function(dataset, var) { var <- assert_symbol(enexpr(var)) assert_date_var(dataset = dataset, var = !!var) @@ -1479,18 +1350,18 @@ test_that("assert_date_var Test 86: error if variable is not a date or datetime }) # assert_date_vector ---- -## Test 87: returns error if input vector is not a date formatted ---- -test_that("assert_date_vector Test 87: returns error if input vector is not a date formatted", { +## Test 80: returns error if input vector is not a date formatted ---- +test_that("assert_date_vector Test 80: returns error if input vector is not a date formatted", { expect_error(assert_date_vector("2018-08-23")) }) -## Test 88: returns invisible if input is date formatted ---- -test_that("assert_date_vector Test 88: returns invisible if input is date formatted", { +## Test 81: returns invisible if input is date formatted ---- +test_that("assert_date_vector Test 81: returns invisible if input is date formatted", { expect_invisible(assert_date_vector(as.Date("2022-10-25"))) }) -## Test 89: no error if `arg` is NULL and optional is TRUE ---- -test_that("assert_date_vector Test 89: no error if `arg` is NULL and optional is TRUE", { +## Test 82: no error if `arg` is NULL and optional is TRUE ---- +test_that("assert_date_vector Test 82: no error if `arg` is NULL and optional is TRUE", { example_fun <- function(arg) { assert_date_vector(arg, optional = TRUE) } @@ -1500,8 +1371,8 @@ test_that("assert_date_vector Test 89: no error if `arg` is NULL and optional is ) }) -## Test 90: error if `arg` is NULL and optional is FALSE ---- -test_that("assert_date_vector Test 90: error if `arg` is NULL and optional is FALSE", { +## Test 83: error if `arg` is NULL and optional is FALSE ---- +test_that("assert_date_vector Test 83: error if `arg` is NULL and optional is FALSE", { example_fun <- function(arg) { assert_date_vector(arg, optional = FALSE) } @@ -1518,8 +1389,8 @@ test_that("assert_date_vector Test 90: error if `arg` is NULL and optional is FA # assert_atomic_vector ---- -## Test 91: error if input is not atomic vector ---- -test_that("assert_atomic_vector Test 91: error if input is not atomic vector", { +## Test 84: error if input is not atomic vector ---- +test_that("assert_atomic_vector Test 84: error if input is not atomic vector", { x <- list("a", "a", "b", "c", "d", "d", 1, 1, 4) expect_error(assert_atomic_vector(x), class = "assert_atomic_vector") expect_snapshot( @@ -1529,15 +1400,15 @@ test_that("assert_atomic_vector Test 91: error if input is not atomic vector", { }) # assert_same_type ---- -## Test 92: no error if same type ---- -test_that("assert_same_type Test 92: no error if same type", { +## Test 85: no error if same type ---- +test_that("assert_same_type Test 85: no error if same type", { true_value <- "Y" false_value <- "N" expect_invisible(assert_same_type(true_value, false_value)) }) -## Test 93: error if different type ---- -test_that("assert_same_type Test 93: error if different type", { +## Test 86: error if different type ---- +test_that("assert_same_type Test 86: error if different type", { true_value <- "Y" false_value <- "N" missing_value <- 0 @@ -1553,8 +1424,8 @@ test_that("assert_same_type Test 93: error if different type", { ) }) -## Test 94: works as intended ---- -test_that("assert_same_type Test 94: works as intended", { +## Test 87: works as intended ---- +test_that("assert_same_type Test 87: works as intended", { expect_equal( valid_time_units(), c("years", "months", "days", "hours", "minutes", "seconds")