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
recode_factor does not handle !!! #3390
Comments
Just adding an example of what we would expect, here: Expect: suppressPackageStartupMessages(library(tidyverse))
set.seed(100)
x <- sample(head(LETTERS, 3), 10, replace = TRUE) %>%
factor
recode_factor(x, B = "Be", C = "Cool", A = "Amigo")
#> [1] Amigo Amigo Be Amigo Be Be Cool Be Be Amigo
#> Levels: Be Cool Amigo Get: level_key <- list(B = "Be", C = "Cool", A = "Amigo")
recode_factor(x, !!!level_key)
#> Error in !level_key: invalid argument type Created on 2018-03-03 by the reprex package (v0.2.0). |
for helping with cross reference, this issue is related to #3388 that was asked before and redirected to community.rstudio.com |
@cderv yeah, I think community served its purpose well— turned out it was a bug, and thus landed back here! 😁 Related: #3218 Oddly enough, it works with suppressPackageStartupMessages(library(tidyverse))
set.seed(100)
x <- sample(head(LETTERS, 3), 10, replace = TRUE) %>%
factor
level_key <- list(B = "Be", C = "Cool", A = "Amigo")
dplyr::recode(x, !!! level_key)
#> [1] Amigo Amigo Be Amigo Be Be Cool Be Be Amigo
#> Levels: Amigo Be Cool Created on 2018-03-25 by the reprex package (v0.2.0). |
- Support `!!!` in `recode_factor()` (#3390).
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
A code snippet like this
produces an error that says !level_key is an invalid argument type
This is the result of a question on https://community.rstudio.com/t/using-recode-factor-with-quasi-quotation/5761/5
Here is a repro
Created on 2018-03-03 by the reprex package (v0.2.0).
The problem is the use of c(...) inside of rcode_factor. Here is my analysis of the problem.
The problem is buried inside of recode_factor. It is that only functions that are implemented to use quosures can properly interpret
!!!
Here is where the problem is in recode_factor:
Created on 2018-03-03 by the reprex package (v0.2.0).
The problem is in the Combine,
c()
, function. Although in!!! layer_key
!!!
looks like an operator or in !!!(layer_key) it looks like a function it is neither.It depends on the function getting the
!!!
layer_key in an...
argument to do something like enquo(...) so that standard evaluation is bypassed. It is enquo(or one of it's friends) that interprets!!!
to turn a list into individual dot arguments.But c() is a primitive function so it just does standard evaluation of
!!! level_key
which, in effect, produces a syntax kind of error.Here is an example of a function that tries to use
!!!
withc()
Created on 2018-03-03 by the reprex package (v0.2.0).
I don't see a workaround for this.
The text was updated successfully, but these errors were encountered: