Skip to content

Clarification on tbl class (before raising issue in ggplot2) #519

Closed
@TimTaylor

Description

@TimTaylor

I've been starting to make more and more use of data frames with class c("tbl", "data.frame") due to the nice formatting pillar provides but ran in to a ggplot2 issue today that I'd appreciate thoughts on before I raise over there (apologies for this but due to your "ownership" of tbl I thought you'd have an opinion and wanted to confirm my understanding of how you view the tbl class).

If you run the following in an environment with no dplyr installation it errors:

library(ggplot2)
x <- y <- seq_len(2L)
dat <- data.frame(x,y)
class(dat) <- c("tbl", class(dat))
ggplot(dat,aes(x,y))+geom_col()
#> Error in `fortify()`:
#> ! The package `dplyr` is required to work with `tbl` objects

Created on 2022-03-25 by the reprex package (v2.0.1)

This is due to this line in ggplot2. This feels odd to me. My inclination is that ggplot2 should either:

  • have specific methods for different classes they want to support and dispatch to the data frame method by default; or
  • Take dplyr to be a hard dependency if they do want to call dplyr::collect() on tbls.

Appreciate any thoughts you may have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions