Home > Enterprise >  How do you find the lifecycle status of a tidyverse function or argument?
How do you find the lifecycle status of a tidyverse function or argument?

Time:11-30

What's the correct way to work out the enter image description here

What I know so far

I guess that the documentation will tell us, for example: library(tidyverse); ?summarise shows the .groups argument as 'experimental'.

Is assuming a function/argument is 'stable' unless it's expressly designated 'experimental', 'deprecated', or 'superseded' correct, or is there a more accurate/easier way to find out whether or not it's 'stable'?

enter image description here

Background

In case it's relevant, the problem I'm trying to solve is that a friend complains of the occasionally deprecated tidyverse function necessitating shiny app maintenance. So I want to suggest they check for 'stable' functions/arguments on their future work to minimise this maintenance. Just after the easiest / most sensible way for them to do that.

CodePudding user response:

A potential solution is to lint your package/script using the lint_tidyverse_lifecycle() function from the lifecycle package to identify 'unstable' functions, e.g.

(In Rstudio):

library(lifecycle)
lint_tidyverse_lifecycle()

Which, in my case, gives me a large number of unstable functions that I need to correct/update/fix:

issues.png

Most of these are very simple changes (i.e. dplyr::sample_n() -> dplyr::slice_sample()) and once all of the issues are addressed, all of the tidyverse functions used in the script will be 'stable'.

CodePudding user response:

For debugging code, see lint_lifecycle, which searches for matches in files. To find the lifecycle of functions (here specifically for the tidyverse), we can make a custom function. Neither of these approaches identify experimental arguments like .groups in summarise. It can then lead to frustrating debugging processes later. For those functions, I'd consider finding an alternative that is stable, for example base R aggregate.

f <- function(type = NULL){
  check_pkgs <- Vectorize(lifecycle:::pkg_lifecycle_statuses, "package")
  pkgs <- tidyverse::tidyverse_packages()
  l <- check_pkgs(pkgs)
  l <- l[lapply(l, length) > 0]
  df <- data.frame(pkg = unlist(l[seq.int(1, length(l), 3)], use.names = F),
                   fun = unlist(l[seq.int(2, length(l), 3)], use.names = F),
                   cycle = unlist(l[seq.int(3, length(l), 3)], use.names = F))
  if(!is.null(type)) subset(df, cycle == type) else df
}

# many functions are "experimental".
f("experimental")

For non-tidyverse functions, we can replace pkgs <- tidyverse_packages() with

att <- .packages()
pkgs <- att[!att %in% rownames(installed.packages(priority="base"))]

And if situation requires it, we can do some manual searching by finding

needles <- f()$fun
haystack <- rstudioapi::getActiveDocumentContext()[["contents"]]

As an aside, there are a few more stages (no longer recommended by lifecycle) that are still used in tidyverse documentation. Choices are superseded, deprecated, questioning, defunct, experimental, soft-deprecated. Further caveats are maturing and retired.

  • Related