{"action":"created","issue":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/3390","repository_url":"https://api.github.com/repos/tidyverse/dplyr","labels_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3390/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3390/comments","events_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3390/events","html_url":"https://github.com/tidyverse/dplyr/issues/3390","id":301995512,"node_id":"MDU6SXNzdWUzMDE5OTU1MTI=","number":3390,"title":"recode_factor does not handle !!!","user":{"login":"dan87134","id":22779142,"node_id":"MDQ6VXNlcjIyNzc5MTQy","avatar_url":"https://avatars3.githubusercontent.com/u/22779142?v=4","gravatar_id":"","url":"https://api.github.com/users/dan87134","html_url":"https://github.com/dan87134","followers_url":"https://api.github.com/users/dan87134/followers","following_url":"https://api.github.com/users/dan87134/following{/other_user}","gists_url":"https://api.github.com/users/dan87134/gists{/gist_id}","starred_url":"https://api.github.com/users/dan87134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan87134/subscriptions","organizations_url":"https://api.github.com/users/dan87134/orgs","repos_url":"https://api.github.com/users/dan87134/repos","events_url":"https://api.github.com/users/dan87134/events{/privacy}","received_events_url":"https://api.github.com/users/dan87134/received_events","type":"User","site_admin":false},"labels":[{"id":276202384,"node_id":"MDU6TGFiZWwyNzYyMDIzODQ=","url":"https://api.github.com/repos/tidyverse/dplyr/labels/data%20frame","name":"data frame","color":"eeeeee","default":false},{"id":17708200,"node_id":"MDU6TGFiZWwxNzcwODIwMA==","url":"https://api.github.com/repos/tidyverse/dplyr/labels/feature","name":"feature","color":"009800","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-03T12:44:31Z","updated_at":"2018-09-22T09:38:12Z","closed_at":"2018-03-26T09:31:24Z","author_association":"NONE","body":"A code snippet like this\r\n\r\n```r\r\ndplyr::recode_factor(x, !!! layer_key)\r\n```\r\nproduces an error that says !level_key is an invalid argument type\r\n\r\nThis is the result of a question on https://community.rstudio.com/t/using-recode-factor-with-quasi-quotation/5761/5\r\n\r\nHere is a repro\r\n\r\n``` r\r\nlibrary(magrittr)\r\nlibrary(dplyr)\r\n#> \r\n#> Attaching package: 'dplyr'\r\n#> The following objects are masked from 'package:stats':\r\n#> \r\n#>     filter, lag\r\n#> The following objects are masked from 'package:base':\r\n#> \r\n#>     intersect, setdiff, setequal, union\r\nset.seed(100)\r\nx <- sample(head(LETTERS, 3), 10, replace = TRUE) %>% factor\r\nx\r\n#>  [1] A A B A B B C B B A\r\n#> Levels: A B C\r\nlevel_key <- list(\"Be\", \"Cool\", \"Amigo\") %>% set_names(c(\"B\", \"C\", \"A\"))    # set factor re-level \r\nlevel_key2 <- list(B = \"Be\", C = \"Cool\", A = \"Amigo\")\r\n\r\ndplyr::recode_factor(x, !!!level_key)\r\n#> Error in !level_key: invalid argument type\r\n```\r\n\r\nCreated on 2018-03-03 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).\r\n\r\nThe problem is the use of c(...) inside of rcode_factor. Here is my analysis of the problem.\r\n\r\nThe problem is buried inside of recode_factor. It is that only functions that are implemented to use quosures can properly interpret `!!!`\r\n\r\nHere is where the problem is in recode_factor:\r\n\r\n``` r\r\ndplyr:::recode_factor\r\n#> function (.x, ..., .default = NULL, .missing = NULL, .ordered = FALSE) \r\n#> {\r\n#>     recoded <- recode(.x, ..., .default = .default, .missing = .missing)\r\n# ----------------------------The . problem is with c() ----\r\n#>     all_levels <- unique(c(..., recode_default(.x, .default, \r\n#>         recoded), .missing))\r\n#>     recoded_levels <- if (is.factor(recoded)) \r\n#>         levels(recoded)\r\n#>     else unique(recoded)\r\n#>     levels <- intersect(all_levels, recoded_levels)\r\n#>     factor(recoded, levels, ordered = .ordered)\r\n#> }\r\n#> <environment: namespace:dplyr>\r\n```\r\nCreated on 2018-03-03 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).\r\n\r\n\r\nThe 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. \r\n\r\nIt 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.\r\n\r\nBut c() is a primitive function so it just does standard evaluation of `!!! level_key` which, in effect, produces a syntax kind of error.\r\n\r\nHere is an example of a function that tries to use `!!!` with `c()`\r\n\r\n``` r\r\n\r\nsuppressPackageStartupMessages(library(tidyverse))\r\nf2 <- function(...) {\r\n    c(...)\r\n}\r\nlevel_key <- list(\"Be\", \"Cool\", \"Amigo\") %>% set_names(c(\"B\", \"C\", \"A\"))    # set factor re-level \r\n\r\nf2(!!! level_key)\r\n#> Error in !level_key: invalid argument type\r\n```\r\n\r\nCreated on 2018-03-03 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).\r\n\r\nI don't see a workaround for this.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/comments/423730837","html_url":"https://github.com/tidyverse/dplyr/issues/3390#issuecomment-423730837","issue_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3390","id":423730837,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzczMDgzNw==","user":{"login":"lock[bot]","id":33595554,"node_id":"MDM6Qm90MzM1OTU1NTQ=","avatar_url":"https://avatars1.githubusercontent.com/in/6672?v=4","gravatar_id":"","url":"https://api.github.com/users/lock%5Bbot%5D","html_url":"https://github.com/apps/lock","followers_url":"https://api.github.com/users/lock%5Bbot%5D/followers","following_url":"https://api.github.com/users/lock%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/lock%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/lock%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lock%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/lock%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/lock%5Bbot%5D/repos","events_url":"https://api.github.com/users/lock%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/lock%5Bbot%5D/received_events","type":"Bot","site_admin":false},"created_at":"2018-09-22T09:38:12Z","updated_at":"2018-09-22T09:38:12Z","author_association":"NONE","body":"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/>\n"}}
{"actor":{"display_login":"lock"}}