I have a situation where I have an unevaluated lazy tibble against a database. Not unlike mtcars2
in the example below:
library(tidyverse)
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
copy_to(con, mtcars)
mtcars2 <- tbl(con, "mtcars") %>%
select(mpg, cyl, gear, hp) %>%
group_by(cyl)
I'd like to test and make sure that a specific column exists in the data frame. I'd also like to check the groupings. How can I do that on a lazy tibble? Since it's unevaluated, names
just returns the list names:
names(mtcars2)
#> [1] "src" "ops"
The field names are, of course, in the tibble structure. But I can't see any easy way to pop them out:
mtcars2$ops$x$dots
#> [[1]]
#> <quosure>
#> expr: ^mpg
#> env: 0x7fbb5a3bb518
#>
#> [[2]]
#> <quosure>
#> expr: ^cyl
#> env: 0x7fbb5a3bb518
#>
#> [[3]]
#> <quosure>
#> expr: ^gear
#> env: 0x7fbb5a3bb518
#>
#> [[4]]
#> <quosure>
#> expr: ^hp
#> env: 0x7fbb5a3bb518