Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #4786.

Briefly, it attempts to exploit that some as.data.frame() methods will implicitly use collect() to realise a local data.frame.
For example:

dbplyr:::as.data.frame.tbl_sql
#> function (x, row.names = NULL, optional = NULL, ..., n = Inf) 
#> {
#>     as.data.frame(collect(x, n = n))
#> }
#> <bytecode: 0x000001b7f118b958>
#> <environment: namespace:dbplyr>

This should ensure that you can still work with e.g. <tbl_sql> classes that will be collect()'ed while not requiring {dplyr} for the fortify.tbl() method. Example demonstrating we can still use lazy data.frames:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
library(dbplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
dplyr::copy_to(con, mtcars)
df <- dplyr::tbl(con, "mtcars")

ggplot(df, aes(mpg, disp)) +
  geom_point()

Created on 2024-07-02 with reprex v2.1.0

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@teunbrand
Copy link
Collaborator Author

Thanks for the review!

@teunbrand teunbrand merged commit b8da7af into tidyverse:main Jul 4, 2024
@teunbrand teunbrand deleted the fortify_tbl branch July 4, 2024 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Requirement of dplyr for non-tibble tbls
2 participants