Skip to content

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

Open
@MichaelChirico

Description

@MichaelChirico

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)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviordocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions