Closed ClaytonJY closed 6 years ago
👍
I'm not sure why it works on the CRAN version, but the current behaviour seems consistent. You can use enexpr()
rather than enquo()
to work around this. case_when()
doesn't currently support quosures.
The interaction between case_when()
and tidy eval functions is very tricky. An overscope is lexically scoped but here we need some dynamic behaviour in order to reuse the existing overscope set up by mutate()
.
I think what we need is a _tidyeval_overscope
flag in the overscope (like the one in the non-formula quosures branch). Then when case_when()
is evaluated in an overscope it can reuse it for its internal evaluation. I think this simple change should solve all evaluation problems with case_when()
.
I'm sorry, case_when()
vs tidy eval confuses me to no end. It should work and I now remember why ;)
Reprex:
quo <- quo(~!!quo(x))
is_quosure(f_rhs(get_expr(quo)))
#> [1] TRUE
f <- eval_tidy(quo)
is_quosure(f_rhs(f))
#> [1] FALSE
Finally fixed. Thanks for the report!
My apologies if this is covered in another bug; couldn't find any obvious matches in the existing issues.
I discovered a useful code-pattern using
dplyr::case_when
insidedplyr::mutate
that works fine inrlang 0.1.1
, but is broken inrlang 0.1.1.9000
:Expected Behaviour (CRAN, 0.1.1)
Actual Behavior (Github master, 0.1.1.9000)
traceback
Couldn't get the whole thing to copy-paste well, but this is the last bit, with parent call
mutate_impl(.data, dots)
:I suppose that suggests this is a C++ internal thing?
I'd be happy to follow-up, try new things, or even write tests, but the C++ internal stuff is a bit beyond me to help fix I think.
Thanks to all for excellent work making it easier to work programatically in the tidyverse; it's a little weird at first, but I'm hooked.