dplyr icon indicating copy to clipboard operation
dplyr copied to clipboard

`across(.names =)` evaluates `"{col}"` as if it was `"{.col}"`

Open arnaudgallou opened this issue 6 months ago • 1 comments

It doesn't seem to be the expected behavior according to the documentation.

col <- "foo"

tibble::tibble(
  x = 1:3,
  y = 4:6
) |> 
  dplyr::mutate(
    dplyr::across(c(x, y), \(.x) .x * 2, .names = "{col}_{.col}")
  )
#> # A tibble: 3 × 4
#>       x     y   x_x   y_y
#>   <int> <int> <dbl> <dbl>
#> 1     1     4     2     8
#> 2     2     5     4    10
#> 3     3     6     6    12

packageVersion("dplyr")
#> [1] '1.1.4'

Created on 2025-06-09 with reprex v2.1.1

arnaudgallou avatar Jun 09 '25 11:06 arnaudgallou

I think it is undocumented but "technically expected" on our end https://github.com/tidyverse/dplyr/blob/be3e3a05fd0081cb53168d6aedb417d62139b75d/R/across.R#L414-L419

We switched to the dot prefix but kept the non-dot versions in this PR https://github.com/tidyverse/dplyr/pull/5448

It looks like dplyr 1.0.0 originally used {col}, and the idea here was that we switched to {.col} and updated all documentation to use {.col}, but kept the old way to avoid breaking anything. At this point we should:

  • Document {col} and {fn} as technically allowed but discouraged
  • Consider starting to deprecate {col} and {fn} usage, as the TODO suggests

DavisVaughan avatar Jun 09 '25 13:06 DavisVaughan