-
Notifications
You must be signed in to change notification settings - Fork 25
More flexible syntax for warning messages #120
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
Comments
Do you have a few more examples where the current syntax isn't sufficient? Or is this specifically about deprecating values? |
The current syntax is sufficient when an argument or a function as a whole is being deprecated. Problems arise when values are no longer supported, or when some behaviour is no longer supported. We've added support for Also the current syntax can't be used when it's not about a function but e.g. a global option. We could extend what = c(message = "Setting the `foo` global option to value...") Here is an example from purrr where a more flexible UI would help: deprecate_warn(
"0.3.0",
what = c("list_modify(...)", message = "Removing elements with `NULL`..."),
with = c(message = "Please use `zap()` to remove elements.")
)
#> Warning message:
#> Removing elements with `NULL` is deprecated as of purrr 0.3.0.
#> Please use `zap()` to remove elements. oh another thing we should do is include #> Warning message:
#> In list_modify() : Removing elements with `NULL` is deprecated as of purrr 0.3.0.
#> Please use `zap()` to remove elements. (With the extra space and lack of backticks because we are not in control of warning display.) |
Why can't we use deprecate_warn(
"0.3.0",
what = I("Removing elements with `NULL`"),
with = I("Please use `zap()` to remove elements.")
) |
Because we need a way to supply metadata in a structured way, i.e. the function name and argument name. This may be useful in the future to inspect properties of warnings. Also, I'm thinking about including the function name as Are you concerned only about the UI or also to the idea of using |
Both the UI and and the use of |
Just had a situation in yardstick where I wanted to deprecate the |
Another case is r-lib/tidyselect#169 — we'd like to be able to say "Using |
One more argument in favour of the Here are the three examples mentioned above in the thread:
Maybe there's a distinction between static and dynamic deprecation? In the vast majority of cases, you could identify the deprecation with a static analysis because we either deprecate an entire function or a specific argument. That's what lifecycle is currently designed for and it does a great job at it. In other cases, like in this issue, we have a deprecation that can only be detected dynamically, and lifecycle isn't such a good fit. Dynamic deprecations tend to be much rarer (~5 vs. ~80) so ideally we could use the existing interface with some minor changes. |
Sounds good, let's go with |
The challenge is to have a flexible UI that still makes it easy to supply the metadata stored in the warning conditions, that is package, function name, and argument name.
One way to go about this is to allow a length-2 vector whose first element defines the metadata, and the second specifies a warning message.
We could use
...
as a placeholder that lifecycle could fill in with generated contents.The
with
argument would also allow amessage
field:I like that this leverages existing syntax for defining a deprecation message + metadata.
What do you think @hadley?
The text was updated successfully, but these errors were encountered: