tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.78k stars 2.12k forks source link

Formulas don't get the right environment within tidyeval functions #2745

Closed daattali closed 7 years ago

daattali commented 7 years ago

The following code is taken straight from the documentation for dplyr::do:

by_cyl <- group_by(mtcars, cyl)
do(by_cyl, head(., 2))

This works.

But if I try to call a filter_ inside the do function, and use a locally defined variable like this:

library(dplyr)
by_cyl <- group_by(mtcars, cyl)
do(by_cyl, {
    foo <- "virginica"
    filter_(iris, ~ Species == foo)
    head(., 2) })

I get error:

Error in filter_impl(.data, quo) : object 'foo' not found

This does not happen in dplyr 0.5

I haven't debugged enough to find out anything more specific, but this is a fairly isolated minimal reproducible bug.

I know that NS_ functions are now deprecated but this will break old code in packages - I assume I'm not the only one affected

lionel- commented 7 years ago

This requires a fix in rlang and unfortunately rlang just got on CRAN. I'll install the fix on master tomorrow.