tidyr 1.0: gather() and spread() are dead

tidyr 1.0 replaces gather() and spread() with pivot_longer() and pivot_wider() — here’s what that means for trainers and self-taught R users.
R
Published

September 18, 2019

{tidyr} version 1.0 has just been released on CRAN in September 2019, 5 years after it’s conception in Hadley Wickham’s seminal Tidy Data paper. While {tidyr} might not get as much love as {dplyr}, it’s the cornerstone of the tidyverse and this new version radically changes things.

All users of the tidyverse should hear these two proclamations:

gather() is dead. Long live pivot_longer().

spread() is dead. Long live pivot_wider().

There’s a new {tidyr} vignette about these “pivoting” functions which explains very simply why these old functions have been retired:

there is something fundamentally wrong with the design of spread() and gather(). Many people don’t find the names intuitive and find it hard to remember which direction corresponds to spreading and which to gathering. […] meaning that many people (including Hadley Wickham) have to consult the documentation every time.

I’m extremely happy about these changes, the new functions are tremendously flexible and nicely named.

But, I also have the following concerns:

To help decide how to approach updating our own courses, I put together the following Twitter poll (which received 196 votes!):

I was quite shocked that just under 50% of respondents were planning to update their training courses immediately. However, if the community does move quickly to update their content then the concerns I raised above will have much less of an impact than I feared.

Course update strategy

In response to this survey data and conversations with other trainers, here are my plans for updating training materials:

  • Wait until January 2020 before making significant changes. While I think the new functions are designed well, there’s precedence for functionality to change significantly after community use. I want to avoid teaching functionality before it has stabilised.

  • Explicitly show students the docs pages whenever gather() and spread() are used. I will not be updating lecture slides about the old functions, but I will show students the docs pages when demonstrating how to use the function.

  • Foster discussion with students about deprecation and new features. I will put aside time to discuss with students how to manage deprecated functions, and encourage questions.

spread()’s dead, baby, spread()’s dead