tidyverse / tidyr

Tidy Messy Data
https://tidyr.tidyverse.org/
Other
1.38k stars 418 forks source link

Breaking change omitted from NEWS: spread(<data.table>) no longer inherits from data.table #1473

Open MichaelChirico opened 1 year ago

MichaelChirico commented 1 year ago

We have some code broken by the update to tidyr 1.3.0 and I don't see the issue mentioned in NEWS so I'm not sure if it's intentional.

I can re-use the example from ?spread to demonstrate:

stocks <- tibble(
  time = as.Date("2009-01-01") + 0:9,
  X = rnorm(10, 0, 1),
  Y = rnorm(10, 0, 2),
  Z = rnorm(10, 0, 4)
)
stocksm <- stocks %>% gather(stock, price, -time)

# <not in ?spread>
data.table::setDT(stocksm)

stocksm %>% spread(stock, price) %>% inherits("data.table")
## ON 1.3.0
# [1] FALSE
## ON 1.2.1
# [1] TRUE

This breaks use cases that e.g. proceed to use [ on the spread() output and assume data.table syntax applies:

# works on 1.2.1, broken on 1.3.0
spread(stocksm, stock, price)[order(X)]
hadley commented 10 months ago

Do you have any sense of whether it's worth fixing this? By the time we get a release out, I'm worried that most people will have adapted so that the net effect will be more pain.

MichaelChirico commented 10 months ago

I don't think a code fix is needed, but a NEWS entry citing this as a potential breaking change still makes sense to me.

hadley commented 10 months ago

Makes sense!