The lifecycle package uses warnings to tell you about deprecated functions. Deprecated functions will be removed in a future release, so it’s good practice to eliminate the warnings as soon as you see them.
For example, lets imagine your code uses tibble::data_frame()
, which was deprecated in favour of tibble()
in version 1.1.0. data_frame()
now looks something like this:
<- function(...) {
data_frame ::deprecate_warn("1.1.0", "data_frame()", "tibble()")
lifecycle::tibble(...)
tibble }
That means if you use data_frame()
in your own code you’ll get a warning:
<- data_frame(x = 1, y = 2)
df1 #> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
<- data_frame(a = "apple", b = "banana")
df2 #> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
You’ll notice that the warning only appears the first time we call it — lifecycle only notifies you every 8 hours so it’s not overly disruptive if you’ve used a deprecated function in many places.
So how do you track down exactly where the warning came from? Firstly, you might notice the deprecation warning message includes the advice to call lifecycle::last_lifecycle_warnings()
. That’ll give you a list of all the deprecation warnings that have happened recently:
::last_lifecycle_warnings()
lifecycle#> [[1]]
#> <deprecated>
#> message: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
#> Backtrace:
#> 1. global::data_frame(x = 1)
Each warning comes with a back trace that shows you the full sequence of calls that lead to the deprecated function.
Alternatively, if you’re ready to spend some time tracking down all your uses of deprecated functions, you can use the lifecycle_verbosity
option to make deprecated functions warn every time:
options(lifecycle_verbosity = "warning")
<- data_frame(x = 1, y = 2)
df1 #> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
<- data_frame(a = "apple", b = "banana")
df2 #> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
Then use lifecycle::last_lifecycle_warnings()
to track down the source.
Alternatively, if you want to be really strict, you can turn all deprecation warnings into errors, forcing you to deal with them immediately:
options("lifecycle_verbosity" = "error")
<- data_frame(x = 1, y = 2)
df1 #> Error: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.