-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Problem with cur_column()
#5892
Comments
library(dplyr, warn.conflicts = FALSE)
d <- tibble(x = 1:2, y = 7:8)
values <- list(x = c("1" = "yes", "2" = "no"),
y = c("7" = "YEs", "8" = "No")
)
f <- function(x) {
recode(x, !!!(values[[(cur_column())]]))
}
d %>%
mutate(across(any_of(names(values)), f))
#> # A tibble: 2 x 2
#> x y
#> <chr> <chr>
#> 1 yes YEs
#> 2 no No Created on 2021-05-26 by the reprex package (v2.0.0) |
I've just stumbled upon a similar issue, but with a different error message that is not helpful at all. Is it possible to somehow inform the user where the culprit is? In this case, there is no library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(forcats)
# fails
tibble(a = factor(c("A1", "A2", "A3"))) |>
mutate(
across(
a,
\(x) {
rename_vec <- c("a" = "A1", "b" = "A2", "c" = "A3")
fct_recode(x, !!!rename_vec)
}
)
)
#> Error: object 'rename_vec' not found
# works
rename_fun <- function(x) {
rename_vec <- c("a" = "A1", "b" = "A2", "c" = "A3")
fct_recode(x, !!!rename_vec)
}
tibble(a = factor(c("A1", "A2", "A3"))) |>
mutate(
across(
a,
rename_fun
)
)
#> # A tibble: 3 × 1
#> a
#> <fct>
#> 1 a
#> 2 b
#> 3 c Created on 2025-02-22 with reprex v2.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
cur_column()
function does not detect the values, using!!!
. I read that in across, some parts may be evaluated too early.Is there a way to replace the
!!!
call in that case?The code works outside across.
Brief description of the problem
Created on 2021-05-21 by the reprex package (v2.0.0)
The text was updated successfully, but these errors were encountered: