Skip to content

Don't require dplyr for fortify.tbl() #5969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2024

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
11 checks passed
@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