-
Notifications
You must be signed in to change notification settings - Fork 25
Improve warnings in indirect usages #137
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
Changes from all commits
10888e3
598384b
e00dbad
6febf95
345aebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,47 +102,69 @@ deprecate_soft <- function(when, | |
| signal_stage("deprecated", what) | ||
|
|
||
| verbosity <- lifecycle_verbosity() | ||
| if (verbosity == "quiet") { | ||
| NULL | ||
| } else if (verbosity %in% c("warning", "default")) { | ||
| if (is_direct(user_env)) { | ||
| always <- verbosity == "warning" | ||
| deprecate_warn0(msg, id, trace_back(bottom = caller_env()), always = always) | ||
| } | ||
| } else if (verbosity == "error") { | ||
| deprecate_stop0(msg) | ||
| } | ||
|
|
||
| invisible(NULL) | ||
| direct <- is_direct(user_env) | ||
|
|
||
| invisible(switch( | ||
| verbosity, | ||
| quiet = NULL, | ||
| warning = , | ||
| default = | ||
| if (direct) { | ||
| always <- verbosity == "warning" | ||
| trace <- trace_back(bottom = caller_env()) | ||
| deprecate_warn0( | ||
| msg, | ||
| id, | ||
| trace, | ||
| always = always, | ||
| direct = TRUE, | ||
| user_env = user_env | ||
| ) | ||
| }, | ||
| error = deprecate_stop0(msg) | ||
| )) | ||
| } | ||
|
|
||
| #' @rdname deprecate_soft | ||
| #' @param always If `FALSE`, the default, will warn every 8 hours. | ||
| #' If `TRUE`, will always warn. Only use `always = TRUE` after at least | ||
| #' one release with the default. | ||
| #' @param always If `FALSE`, the default, will warn every 8 hours. If | ||
| #' `TRUE`, will always warn in direct usages. Indirect usages keep | ||
| #' warning every 8 hours to avoid disrupting users who can't fix the | ||
| #' issue. Only use `always = TRUE` after at least one release with | ||
| #' the default. | ||
| #' @export | ||
| deprecate_warn <- function(when, | ||
| what, | ||
| with = NULL, | ||
| details = NULL, | ||
| id = NULL, | ||
| always = FALSE, | ||
| env = caller_env()) { | ||
| env = caller_env(), | ||
| user_env = caller_env(2)) { | ||
| msg <- NULL # trick R CMD check | ||
| msg %<~% lifecycle_message(when, what, with, details, env, "deprecate_warn") | ||
| signal_stage("deprecated", what) | ||
|
|
||
| verbosity <- lifecycle_verbosity() | ||
| if (verbosity == "quiet") { | ||
| NULL | ||
| } else if (verbosity %in% c("default", "warning")) { | ||
| always <- always || verbosity == "warning" | ||
| deprecate_warn0(msg, id, trace_back(bottom = caller_env()), always = always) | ||
| } else if (verbosity == "error") { | ||
| deprecate_stop0(msg) | ||
| } | ||
|
|
||
| invisible(NULL) | ||
| invisible(switch( | ||
| verbosity, | ||
| quiet = NULL, | ||
| warning = , | ||
| default = { | ||
| direct <- is_direct(user_env) | ||
| always <- direct && (always || verbosity == "warning") | ||
| trace <- trace_back(bottom = caller_env()) | ||
| deprecate_warn0( | ||
| msg, | ||
| id, | ||
| trace, | ||
| always = always, | ||
| direct = direct, | ||
| user_env = user_env | ||
| ) | ||
| }, | ||
| error = deprecate_stop0(msg), | ||
| )) | ||
| } | ||
|
|
||
| #' @rdname deprecate_soft | ||
|
|
@@ -164,7 +186,9 @@ deprecate_warn0 <- function(msg, | |
| id = NULL, | ||
| trace = NULL, | ||
| always = FALSE, | ||
| call = caller_env()) { | ||
| direct = FALSE, | ||
| call = caller_env(), | ||
| user_env = caller_env(2)) { | ||
| id <- id %||% msg | ||
| if (!always && !needs_warning(id, call = call)) { | ||
| return() | ||
|
|
@@ -174,12 +198,34 @@ deprecate_warn0 <- function(msg, | |
| env_poke(deprecation_env, id, Sys.time()) | ||
|
|
||
| footer <- function(...) { | ||
| footer <- NULL | ||
|
|
||
| if (!direct) { | ||
| top <- topenv(user_env) | ||
|
|
||
| if (is_namespace(top)) { | ||
| pkg <- ns_env_name(top) | ||
| footer <- c( | ||
| footer, | ||
| "i" = cli::format_inline( | ||
| "The deprecated feature was likely used in the {.pkg {pkg}} package." | ||
| ), | ||
| " " = cli::format_inline( | ||
| "Please report the issue to the authors." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be scope create, but is it worth doing some lightweight parsing of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup I'll take a look, and also do it in |
||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if (is_interactive()) { | ||
| c( | ||
| footer <- c( | ||
| footer, | ||
| if (!always) silver("This warning is displayed once every 8 hours."), | ||
| silver("Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.") | ||
| ) | ||
| } | ||
|
|
||
| footer | ||
| } | ||
| wrn <- new_deprecated_warning(msg, trace, footer = footer) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # nocov start --- compat-zeallot --- 2020-11-23 | ||
|
|
||
| # This drop-in file implements a simple version of zeallot::`%<-%`. | ||
| # Please find the most recent version in rlang's repository. | ||
|
|
||
|
|
||
| `%<-%` <- function(lhs, value) { | ||
| lhs <- substitute(lhs) | ||
| env <- caller_env() | ||
|
|
||
| if (!is_call(lhs, "c")) { | ||
| abort("The left-hand side of `%<-%` must be a call to `c()`.") | ||
| } | ||
|
|
||
| vars <- as.list(lhs[-1]) | ||
|
|
||
| if (length(value) != length(vars)) { | ||
| abort("The left- and right-hand sides of `%<-%` must be the same length.") | ||
| } | ||
|
|
||
| for (i in seq_along(vars)) { | ||
| var <- vars[[i]] | ||
| if (!is_symbol(var)) { | ||
| abort(paste0("Element ", i, " of the left-hand side of `%<-%` must be a symbol.")) | ||
| } | ||
|
|
||
| env[[as_string(var)]] <- value[[i]] | ||
| } | ||
|
|
||
| invisible(value) | ||
| } | ||
|
|
||
|
|
||
| # nocov end |
Uh oh!
There was an error while loading. Please reload this page.