I'd like to group_by
across
several variables in dtplyr
within a lapply
loop, and I find that I somehow can't use the same syntax as dplyr
after calling lazy_dt()
.
library(dplyr)
mycolumns= c("Wind", "Month", "Ozone", "Solar.R")
columnpairs <- as.data.frame(combn(mycolumns, 2))
# V1 V2 V3 V4 V5 V6
# 1 Wind Wind Wind Month Month Ozone
# 2 Month Ozone Solar.R Ozone Solar.R Solar.R
result_dplyr <- lapply(columnpairs, function(x) {
airquality %>%
select(all_of(x)) %>%
group_by(across(all_of(x))) %>% filter(n() > 1)
}
)
$V1
# A tibble: 105 x 2
# Groups: Wind, Month [40]
Wind Month
<dbl> <int>
1 7.4 5
2 8 5
3 11.5 5
4 14.9 5
5 8.6 5
6 8.6 5
7 9.7 5
8 11.5 5
9 12 5
10 11.5 5
# ... with 95 more rows
Using the same syntax, I encounter an issue after calling lazy_dt
with dtplyr
.
library(dtplyr)
airq <- lazy_dt(airquality)
lapply(columnpairs, function(x) {
airq %>% select(all_of(x)) %>%
group_by(across(all_of(x))) %>% filter(n() > 1)
})
Error in `all_of()`:
! object 'x' not found
Any idea?
EDIT: issue created at https://github.com/tidyverse/dtplyr/issues/383