mit einem Klick
tidy-deprecate-function
// Guide for deprecating R functions/arguments. Use when a user asks to deprecate a function or parameter, including adding lifecycle warnings, updating documentation, adding NEWS entries, and updating tests.
// Guide for deprecating R functions/arguments. Use when a user asks to deprecate a function or parameter, including adding lifecycle warnings, updating documentation, adding NEWS entries, and updating tests.
| name | tidy-deprecate-function |
| description | Guide for deprecating R functions/arguments. Use when a user asks to deprecate a function or parameter, including adding lifecycle warnings, updating documentation, adding NEWS entries, and updating tests. |
Use this skill when deprecating functions or function parameters in dbplyr.
This skill guides you through the complete process of deprecating a function or parameter, ensuring all necessary changes are made consistently:
lifecycle::deprecate_warn().Read the current version from DESCRIPTION and calculate the deprecation version:
MAJOR.MINOR.PATCH.9000 (development).MAJOR.(MINOR+1).0.2.5.1.9000, deprecation version is 2.6.0.lifecycle::deprecate_warn() callAdd the deprecation warning to the function:
# For a deprecated function:
function_name <- function(...) {
lifecycle::deprecate_warn("X.Y.0", "function_name()", "replacement_function()")
# rest of function
}
# For a deprecated parameter:
function_name <- function(param1, deprecated_param = deprecated()) {
if (lifecycle::is_present(deprecated_param)) {
lifecycle::deprecate_warn("X.Y.0", "function_name(deprecated_param)")
}
# rest of function
}
Key points:
lifecycle::is_present() to check if a deprecated parameter was supplied.Find all existing tests that use the deprecated function or parameter and silence lifecycle warnings. Add at the beginning of test blocks that use the deprecated feature:
test_that("existing test with deprecated feature", {
withr::local_options(lifecycle_verbosity = "quiet")
# existing test code
})
Then add a new test to verify the deprecation message in the appropriate test file (usually tests/testthat/test-{name}.R):
test_that("function_name(deprecated_param) is deprecated", {
expect_snapshot(. <- function_name(deprecated_param = value))
})
You'll need to supply any additional arguments to create a valid call.
Then run the tests and verify they pass.
For function deprecation, add to the description section:
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function is deprecated. Please use [replacement_function()] instead.
If the documentation does not already contain @description, you will need to add it.
For argument deprecation, add to the appropriate @param tag:
#' @param deprecated_param `r lifecycle::badge("deprecated")`
When deprecating a function or parameter in favor of a replacement, add old/new examples to the @examples section to help users migrate. These should relace all existing examples.
#' @examples
#' # Old:
#' old_function(arg1, arg2)
#' # New:
#' replacement_function(arg1, arg2)
#'
#' # Old:
#' x <- "value"
#' old_function("prefix", x, "suffix")
#' # New:
#' replacement_function("prefix {x} suffix")
Key points:
Then re-document the package.
Add a bullet point to the top of the "# dbplyr (development version)" section in NEWS.md:
# dbplyr (development version)
* `function_name(parameter)` is deprecated and will be removed in a future
version.
* `function_name()` is deprecated. Use `replacement_function()` instead.
Place the entry:
When deprecating a function or parameter, ensure you:
lifecycle::deprecate_warn() call in the function.withr::local_options(lifecycle_verbosity = "quiet") to existing tests.expect_snapshot().@examples section (for function deprecation).devtools::document() to update documentation.air format . to format code.Detect and list all metric functions in the yardstick package. Use when a user asks to find, list, or identify all metrics in the package.
Guide for creating new Claude Code skills. Use when you need to create a new skill to package expertise or workflow into a reusable capability that Claude can automatically invoke.