tidyverse 2.0.0

  tidyverse

  Hadley Wickham

We’re tickled pink to announce the release of tidyverse 2.0.0. The tidyverse is a set of packages that work in harmony because they share common data representations and API design. The tidyverse package is a “meta” package designed to make it easy to install and load core packages from the tidyverse in a single command. This is great for teaching and interactive use, but for package-development purposes we recommend that authors import only the specific packages that they use. For a complete list of changes, please see the release notes.

You can install it from CRAN with:

install.packages("tidyverse")

There’s only really one big change in tidyverse 2.0.0: lubridate is now a core member of the tidyverse! This means it’s attached automatically when you load the tidyverse:

library(tidyverse)
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
#>  dplyr     1.1.0.9000      readr     2.1.4     
#>  forcats   1.0.0           stringr   1.5.0     
#>  ggplot2   3.4.1           tibble    3.1.8     
#>  lubridate 1.9.2           tidyr     1.3.0     
#>  purrr     1.0.1          
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#>  dplyr::filter() masks stats::filter()
#>  dplyr::lag()    masks stats::lag()
#>  Use the conflicted package to force all conflicts to become errors

You’ll notice one other small change to the tidyverse message: we now advertise the conflicted package. This package has been around for a while, but we wanted to promote it a bit more heavily because it’s so useful.

conflicted provides an alternative conflict resolution strategy, when multiple packages export a function of the same name. R’s default conflict resolution system gives precedence to the most recently loaded package. This can make it hard to detect conflicts, particularly when they’re introduced by an update to an existing package. conflicted takes a different approach, turning conflicts into errors and forcing you to choose which function to use.

To use conflicted, all you need to do is load it:

Using any function that’s defined in multiple packages will now throw an error:

filter(mtcars, cyl == 8)
#> Error:
#> ! [conflicted] filter found in 2 packages.
#> Either pick the one you want with `::`:
#>  dplyr::filter
#>  stats::filter
#> Or declare a preference with `conflicts_prefer()`:
#>  `conflicts_prefer(dplyr::filter)`
#>  `conflicts_prefer(stats::filter)`

As the error suggests, to resolve the problem you can either namespace individual calls:

dplyr::filter(mtcars, am & cyl == 8)
#>                 mpg cyl disp  hp drat   wt qsec vs am gear carb
#> Ford Pantera L 15.8   8  351 264 4.22 3.17 14.5  0  1    5    4
#> Maserati Bora  15.0   8  301 335 3.54 3.57 14.6  0  1    5    8

Or declare a session wide preference:

conflicts_prefer(dplyr::filter())
#> [conflicted] Will prefer dplyr::filter over any other package.
filter(mtcars, am & cyl == 8)
#>                 mpg cyl disp  hp drat   wt qsec vs am gear carb
#> Ford Pantera L 15.8   8  351 264 4.22 3.17 14.5  0  1    5    4
#> Maserati Bora  15.0   8  301 335 3.54 3.57 14.6  0  1    5    8

The conflicted package is fairly established, but it hasn’t seen a huge amount of use, so if you think of something that would make it better, please let us know!.