Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

tidyverse

What's the correct way to work out the lifecycle stage of tidyverse functions? (that is, whether the function/argument is considered stable, experimental, deprecated, or superseded)

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.

like image 343
stevec Avatar asked Nov 29 '21 03:11

stevec


People also ask

What are the four stages of the tidyverse lifecycle?

This vignette describes the four primary stages of the tidyverse lifecycle: stable, deprecated, superseded, and experimental. A diagram showing the transitions between the four main stages: experimental can become stable and stable can become deprecated or superseded.

What is the tidyverse in R?

The tidyverse is a set of packages that work in harmony because they share common data representations and API design. The tidyverse package is designed to make it easy to install and load core packages from the tidyverse in a single command. If you’d like to learn how to use the tidyverse effectively, the best place to start is R for data science.

What is the use of tidyverse?

Overview The tidyverse is a set of packages that work in harmony because they share common data representations and API design. The tidyverse package is designed to make it easy to install and load core packages from the tidyverse in a single command.

What are the tidyverse libraries?

library (tidyverse) will load the core tidyverse packages: 1 ggplot2, for data visualisation. 2 dplyr, for data manipulation. 3 tidyr, for data tidying. 4 readr, for data import. 5 purrr, for functional programming. 6 tibble, for tibbles, a modern re-imagining of data frames. 7 stringr, for strings. 8 forcats, for factors. More ...


2 Answers

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'.

like image 108
jared_mamrot Avatar answered Oct 23 '22 10:10

jared_mamrot


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.

like image 3
Donald Seinen Avatar answered Oct 23 '22 10:10

Donald Seinen