Skip to content

Requirement of dplyr for non-tibble tbls #4786

Closed
@TimTaylor

Description

@TimTaylor

Due to the fortify method for <tbl> objects, {dplyr} is require for plotting with non-tibble <tbl> classes:

ggplot2/R/fortify.r

Lines 19 to 22 in 0e64d9c

fortify.tbl <- function(model, data, ...) {
check_installed("dplyr", reason = "to work with `tbl` objects")
dplyr::collect(model)
}

I view {pillar} and the <tbl> subclass as mainly for formatting so wondered if it would be possible to simply dispatch to the next data.frame method and have explicit methods for other <tbl> sub-classes that need supporting separately.

I've also raised this in the pillar repo to get their opinion of how best to view the class.

Hope this all makes sense. Example below (on install where dplyr is removed)

library(tibble)
library(ggplot2)

x <- y <- 1:2
tbl <- dat <- data.frame(x, y)
class(tbl) <- c("tbl", "data.frame")
tbl
#> # A data frame: 2 × 2
#>       x     y
#>   <int> <int>
#> 1     1     1
#> 2     2     2

# this errors
ggplot(tbl, aes(x,y)) + geom_col()
#> Error: dplyr must be installed to work with tbl objects

# this will print ok
ggplot(as_tibble(dat), aes(x,y)) + geom_col()

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions