{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 livepivot_longer().
spread()is dead. Long livepivot_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:
It will take several years before these new functions permeate StackOverflow, blogs and the wider useR community. Self-taught users (like myself) are more likely to copy and paste from StackOverflow than from the docs. These users will likely completely miss out on the new functions and feel frustrated in the future at having learned out-dated practices.
gather()andspread()aren’t actually dead, they’ve just been retired. I’m confident that we’ll see Frankensteinian combinations of the old and new functions in the wild for many years.What do we do with our existing training materials? Should we update all our old training courses or trust users to find the documentation/vignette eventually?
To help decide how to approach updating our own courses, I put together the following Twitter poll (which received 196 votes!):
If you’re an #rstats instructor, when do you intend to update your courses as follows?
— Charlie Joey Hadley (@charliejhadley) September 14, 2019
gather() -> pivot_longer()
spread() -> pivot_wider()
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()andspread()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
"spread()'s dead, baby. spread()'s dead." pic.twitter.com/BDX4dueMrv
— Hlynur Hallgrímsson (@hlynur) September 18, 2019