0 %ˆÂ“þYmõœlH ÒÉ!›Ù«þÆÁÀÅ 474¿ÄÃÚ‹�S»ŽÛ0ìý _“‚ÔŠšTÉ¥Hq@€4ÆJ¢lêA*|œ@nwÈ7î3ܺ³ô_YI9ãb¥JGpg–³³Ã/r';œA.áæg&EÁwa«dn3³ذx²c; •ÂÒ®VqÎï“�ž /ý/âXÍTXp¥Íâh¬¯âT%3ô›ÛÕýSŽ Œ `81°ÃÉu¨=èN–So)Ì„ˆÓÄ ®«<Ñ<Ü€5»GiäT†õ,c›³{ž±0S Ë·hëÍBÏên|óM{¶�¿ùÓ a„"Բš{Ìèü®UÞ¥5NRàûkf-34\ŠWöùX§¯×(ÞÎõ…´[ ¼Ô‡ÚHN>Œ‹™—PsmLîdû‹þá1€Êœ�ª‚F’¹äª—)fÞÑ~Œ5X.=ˆöŠÖ—�ï�i·Æµì°‰¢Ëmñ#‡è†QðšE³~½Nþ‹G˜,”|¦Õœ‚c ï\VÛáñízð §9a�zx�£#s\8èéP[‚æý3Eó† 2J¡‘Š5!Ü9¼@s>îÈSë�®�|¡¶h áü˜ÿÑemúçöâök$Ã…àïL·ç#õú÷wùƒÿ Š´B/Y7 ˆl–ßi~”TÔD¨ Jû�µq—ÔÅ£�þY±¬ÙG­3¤l€þÇ „šÆÅÄ0{ --- title: "Communicate lifecycle changes in your functions" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Communicate lifecycle changes in your functions} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) options( # Pretend we're in the lifecycle package "lifecycle:::calling_package" = "lifecycle", # suppress last_lifecycle_warnings() message by default "lifecycle_verbosity" = "warning" ) ``` lifecycle provides a standard way to document the lifecycle stages of functions and arguments, paired with tools to steer users away from deprecated functions. Before we go in to the details, make sure that you're familiar with the lifecycle stages as described in `vignette("stages")`. ## Basics lifecycle badges make it easy for users to see the lifecycle stage when reading the documentation. To use the badges, first call `usethis::use_lifecycle()` to embed the badge images in your package (you only need to do this once), then use `lifecycle::badge()` to insert a badge: ```{r, eval = FALSE} #' `r lifecycle::badge("experimental")` #' `r lifecycle::badge("deprecated")` #' `r lifecycle::badge("superseded")` ``` Deprecated functions also need to advertise their status when run. lifecycle provides `deprecate_warn()` which takes three main arguments: - The first argument, `when`, gives the version number when the deprecation occurred. - The second argument, `what`, describes exactly what was deprecated. - The third argument, `with`, provides the recommended alternative. We'll cover the details shortly, but here are a few sample uses: ```{r} lifecycle::deprecate_warn("1.0.0", "old_fun()", "new_fun()") lifecycle::deprecate_warn("1.0.0", "fun()", "testthat::fun()") lifecycle::deprecate_warn("1.0.0", "fun(old_arg)", "fun(new_arg)") ``` (Note that the message includes the package name --- this is automatically discovered from the environment of the calling function so will not work unless the function is called from the package namespace.) The following sections describe how to use lifecycle badges and functions together to handle a variety of common development tasks. ## Functions ### Deprecate a function First, add a badge to the the `@description` block[^1]. Briefly describe why the deprecation occurred and what to use instead. [^1]: We only use an explicit `@description` when the description will be multiple paragraphs, as in these examples. ```{r} #' Add two numbers #' #' @description #' `r lifecycle::badge("deprecated")` #' #' This function was deprecated because we realised that it's #' a special case of the [sum()] function. ``` Next, update the examples to show how to convert from the old usage to the new usage: ```{r} #' @examples #' add_two(1, 2) #' # -> #' sum(1, 2) ``` Then add `@keywords internal` to remove the function from the documentation index. If you use pkgdown, also check that it's no longer listed in `_pkgdown.yml`. These changes reduce the chance of new users coming across a deprecated function, but don't prevent those who already know about it from referring to the docs. ```{r} #' @keywords internal ``` You're now done with the docs, and it's time to add a warning when the user calls your function. Do this by adding call to `deprecate_warn()` on the first line of the function: ```{r} add_two <- function(x, y) { lifecycle::deprecate_warn("1.0.0", "add_two()",