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 #264, #288 cleanup assertions and continue deprecation process #289

Merged
merged 16 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ export(is_order_vars)
export(is_valid_dtc)
export(left_join)
export(process_set_values_to)
export(quo_c)
export(quo_not_missing)
export(remove_tmp_vars)
export(replace_symbol_in_expr)
export(replace_symbol_in_quo)
export(replace_values_by_names)
export(squote)
export(suppress_warning)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

## Breaking Changes

- The following functions/arguments have been deprecated from previous admiral versions using the next phase of the deprecation process: (#288)
- `assert_order_vars()`
- `quo_c()`
- `quo_not_missing()`
- `replace_symbol_in_quo()`
- The `quosures` argument was replaced by the `expressions` argument in `replace_values_by_names()`, `get_source_vars()`, and `vars2chr()`. (#288)
- `assert_function_param()` was deprecated in favor of `assert_function()`. (#264)
- `assert_named_expr()` was deprecated in favor of `assert_expr_list()`. (#264)
- `assert_has_variables()` was deprecated in favor of `assert_data_frame()`. (#264)

## Documentation

- Guidance around issues and merging updated (#286)
Expand Down
108 changes: 34 additions & 74 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,7 @@ assert_vars <- function(arg, expect_names = FALSE, optional = FALSE) {
assert_order_vars <- function(arg, optional = FALSE) {
assert_logical_scalar(optional)

deprecate_warn("0.4.0", "assert_order_vars()", "assert_expr_list()")

assert_expr_list(arg, optional = optional)
deprecate_stop("0.4.0", "assert_order_vars()", "assert_expr_list()")
}

#' Is an Argument an Integer Scalar?
Expand Down Expand Up @@ -871,41 +869,35 @@ 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 assertion
#' @family assertion
#' @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) {
assert_logical_scalar(optional)

if (optional && is.null(arg)) {
return(invisible(arg))
}

if (!is.list(arg) ||
!all(map_lgl(arg, ~ is.language(.x) | is.logical(.x))) ||
any(names(arg) == "")) {
err_msg <- sprintf(
"`%s` must be a named list of expressions created using `rlang::exprs()` but is %s",
arg_name(substitute(arg)),
what_is_it(arg)
)
abort(err_msg)
}

invisible(arg)
deprecate_warn("0.5.0", "assert_named_exprs()", "assert_expr_list()", always = TRUE)
assert_expr_list(arg = arg, named = TRUE)
}

#' 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
#'
Expand All @@ -915,38 +907,29 @@ assert_named_exprs <- function(arg, optional = FALSE) {
#'
#' @export
#'
#' @keywords assertion
#' @family assertion
#' @examples
#' library(admiral.test)
#' data(admiral_dm)
#'
#' assert_has_variables(admiral_dm, "STUDYID")
#'
#' try(assert_has_variables(admiral_dm, "AVAL"))
#' @keywords deprecated
#' @family deprecated
Comment on lines +910 to +911
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind deleting the examples to follow our deprecation strategy?

image

assert_has_variables <- function(dataset, required_vars) {
is_missing <- !required_vars %in% colnames(dataset)
if (any(is_missing)) {
missing_vars <- required_vars[is_missing]
if (length(missing_vars) == 1L) {
err_msg <- paste0("Required variable `", missing_vars, "` is missing.")
} else {
err_msg <- paste0(
"Required variables ",
enumerate(missing_vars),
" are missing."
)
}
abort(err_msg)
}
invisible(dataset)
deprecate_warn("0.5.0", "assert_has_variables()", "assert_data_frame()")
assert_data_frame(
arg = dataset,
required_vars = set_names(
exprs(!!!syms(required_vars)),
names(required_vars)
)
)
}

#' Is Argument a Function?
#'
#' Checks if the argument is a function and if all expected arguments are
#' provided by the function.
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function is *deprecated*, please use `assert_function_param()` instead.
#'
#' @param arg A function argument to be checked
#'
#' @param params A character vector of expected argument names
Expand All @@ -965,8 +948,8 @@ assert_has_variables <- function(dataset, required_vars) {
#'
#' @export
#'
#' @keywords assertion
#' @family assertion
#' @keywords deprecated
#' @family deprecated
#' @examples
#' example_fun <- function(fun) {
#' assert_function(fun, params = c("x"))
Expand Down Expand Up @@ -1029,32 +1012,9 @@ assert_function <- function(arg, params = NULL, optional = FALSE) {
#' the function given by `arg`
#'
#' @export
#'
#' @examples
#' hello <- function(name) {
#' print(sprintf("Hello %s", name))
#' }
#'
#' assert_function_param("hello", "name")
#'
#' try(assert_function_param("hello", "surname"))
assert_function_param <- function(arg, params) {
assert_character_scalar(arg)
assert_character_vector(params)
fun <- match.fun(arg)

is_param <- params %in% names(formals(fun))
if (!all(is_param)) {
txt <- if (sum(!is_param) == 1L) {
"%s is not an argument of `%s()`"
} else {
"%s are not arguments of `%s()`"
}
err_msg <- sprintf(txt, enumerate(params[!is_param]), arg)
abort(err_msg)
}

invisible(arg)
deprecate_warn("0.5.0", "assert_function_param()", "assert_function()", always = TRUE)
assert_function(arg = arg, params = params)
}

#' Asserts That a Parameter is Provided in the Expected Unit
Expand Down
3 changes: 1 addition & 2 deletions R/dev_utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ contains_vars <- function(arg) {
#' vars2chr(exprs(USUBJID, AVAL))
vars2chr <- function(expressions, quosures) {
if (!missing(quosures)) {
deprecate_warn(
deprecate_stop(
"0.10.0",
"vars2chr(quosures = )",
"vars2chr(expressions = )"
)
expressions <- map(quosures, rlang::quo_get_expr)
}
rlang::set_names(
map_chr(expressions, as_string),
Expand Down
3 changes: 1 addition & 2 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ get_duplicates <- function(x) {
#' @export
get_source_vars <- function(expressions, quosures) {
if (!missing(quosures)) {
deprecate_warn(
deprecate_stop(
"0.10.0",
"get_source_vars(quosures = )",
"get_source_vars(expressions = )"
)
expressions <- map(quosures, rlang::quo_get_expr)
}
assert_varval_list(expressions, optional = TRUE)

Expand Down
86 changes: 0 additions & 86 deletions R/quo.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
#' Concatenate One or More Quosure(s)
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This function is *deprecated*, please use `expr_c()` instead.
#'
#' @param ... One or more objects of class `quosure` or `quosures`
#'
#' @return An object of class `quosures`
#'
#'
#' @keywords deprecated
#' @family deprecated
#'
#' @export
quo_c <- function(...) {
deprecate_stop(
"0.3.0",
"quo_c()",
"expr_c()",
details = paste(
"Expressions created by `exprs()` must be used",
"instead of quosures created by `vars()`."
)
)
}

#' Concatenate One or More Expressions
#'
#' @param ... One or more expressions or list of expressions
Expand Down Expand Up @@ -53,30 +26,6 @@ expr_c <- function(...) {
inputs[!is_null]
}

#' Check Whether an Argument Is Not a Quosure of a Missing Argument
#'
#' @param x Test object
#'
#' @return TRUE or error.
#'
#'
#' @keywords deprecated
#' @family deprecated
#'
#' @export
quo_not_missing <- function(x) {
deprecate_stop(
"0.3.0",
"quo_not_missing()",
details = paste(
"Due to changing from `vars()` to `exprs()` the function is no longer required.",
"It will be removed in future.",
sep = "\n"
)
)
}


#' Replace Expression Value with Name
#'
#' @param expressions A list of expressions
Expand All @@ -101,7 +50,6 @@ replace_values_by_names <- function(expressions, quosures) {
"replace_values_by_names(quosures = )",
"replace_values_by_names(expressions = )"
)
expressions <- map(quosures, rlang::quo_get_expr)
}
if (is.null(names(expressions))) {
return(expressions)
Expand All @@ -114,40 +62,6 @@ replace_values_by_names <- function(expressions, quosures) {
})
}

#' Replace Symbols in a Quosure
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This function is *deprecated*, please use `replace_symbol_in_expr()` instead.
#'
#' @param quosure Quosure
#'
#' @param target Target symbol
#'
#' @param replace Replacing symbol
#'
#'
#' @return The quosure where every occurrence of the symbol `target` is replaced
#' by `replace`
#'
#' @keywords deprecated
#' @family deprecated
#'
#' @export
replace_symbol_in_quo <- function(quosure,
target,
replace) {
deprecate_stop(
"0.3.0",
"replace_symbol_in_quo()",
"replace_symbol_in_expr()",
details = paste(
"Expressions created by `exprs()` must be used",
"instead of quosures created by `vars()`."
)
)
}

#' Replace Symbols in an Expression
#'
#' Replace symbols in an expression
Expand Down
5 changes: 3 additions & 2 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandoc: 2.11.4
pandoc: 2.19.2
pkgdown: 2.0.7
pkgdown_sha: ~
articles:
Expand All @@ -7,10 +7,11 @@ articles:
git_usage: git_usage.html
pr_review_guidance: pr_review_guidance.html
programming_strategy: programming_strategy.html
rcmd_issues: rcmd_issues.html
release_strategy: release_strategy.html
unit_test_guidance: unit_test_guidance.html
writing_vignettes: writing_vignettes.html
last_built: 2023-04-12T17:21Z
last_built: 2023-06-26T16:08Z
urls:
reference: https://pharmaverse.github.io/admiraldev/devel/reference
article: https://pharmaverse.github.io/admiraldev/devel/articles
Expand Down
3 changes: 0 additions & 3 deletions man/assert_atomic_vector.Rd

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

3 changes: 0 additions & 3 deletions man/assert_character_scalar.Rd

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

3 changes: 0 additions & 3 deletions man/assert_character_vector.Rd

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

Loading
Loading