Skip to content
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

cur_column inside across Error #5809

Closed
iagogv3 opened this issue Mar 10, 2021 · 3 comments
Closed

cur_column inside across Error #5809

iagogv3 opened this issue Mar 10, 2021 · 3 comments
Labels
reprex needs a minimal reproducible example

Comments

@iagogv3
Copy link

iagogv3 commented Mar 10, 2021

I am doing

anscombe %>% mutate(across(c(y1:y4), ~ if_else(!!sym(sub("y", "x", cur_column())) > 10, ., !!sym(sub("y", "x", cur_column())))))
Error: `cur_column()` must only be used inside `across()`.
Backtrace:
  1. `%>%`(...)
 15. dplyr::cur_column()
 16. dplyr:::peek_column()
 17. dplyr:::context_peek("column", "cur_column()", "`across()`")
 18. context_peek_bare(name) %||% abort(glue("`{fun}` must only be used inside {location}."))

So, I am using cur_column inside across but i get

Error: `cur_column()` must only be used inside `across()`.

Is it expected? Could this be solved? There is another option to do the same?

Thank you!

@iagogv3 iagogv3 changed the title cur_column inside across cur_column inside across Error Mar 10, 2021
@romainfrancois romainfrancois added this to the 1.0.6 milestone Mar 10, 2021
@romainfrancois romainfrancois added the reprex needs a minimal reproducible example label Mar 10, 2021
@iagogv3
Copy link
Author

iagogv3 commented Mar 10, 2021

Well, I got answer for my third question, replacing !!sym by get, it works.

@romainfrancois
Copy link
Member

!! is being picked up by mutate() so too early. I think it's one of these cases where it makes sense to write the function outside of the across() call, and so it naturally would discourage the use of !!.

@romainfrancois romainfrancois removed this from the 1.0.6 milestone Mar 10, 2021
@iagogv3
Copy link
Author

iagogv3 commented Mar 10, 2021

Yes, I think it has to something to do with r-lib/rlang#845 , which I had already found previously (r-lib/rlang#321 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants