Skip to content

Problem with cur_column() #5892

@olivroy

Description

@olivroy

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

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")
      )

d %>% 
    mutate(across(any_of(names(values)),
                  .fn = ~ recode(., !!!(values[[(cur_column())]])))
    )
#> Error: `cur_column()` must only be used inside `across()`.
d %>% mutate(x = recode(x, !!!(values[["x"]])))
#> # A tibble: 2 x 2
#>   x         y
#>   <chr> <int>
#> 1 yes       7
#> 2 no        8

Created on 2021-05-21 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions