m-sostero · GitHub

across() uses .fns = as the argument to supply an anonymous function.
This is different than the scoped mutate functions, which used .funs =, with an extra "u".

This causes some problems when rewriting code from scoped syntax mutate_at(.funs = ~) to the new mutate(across(.fns = ~)), because supplying the wrong argument in across() (namely, .funs instead of .fns) fails silently, as shown below.

library(tidyverse)
mtcars <- as_tibble(mtcars) %>% select(mpg)
# Using the named argument ".fns" applies the function, as expected
mtcars %>% mutate(across(mpg, .fns = ~ . * 1000))
#> # A tibble: 32 × 1
#>      mpg
#>    <dbl>
#>  1 21000
#>  2 21000
#>  3 22800
#>  4 21400
#>  5 18700
#>  6 18100
#>  7 14300
#>  8 24400
#>  9 22800
#> 10 19200
#> # … with 22 more rows
# Using the named argument ".funs" fails, silently
mtcars %>% mutate(across(mpg, .funs = ~ . * 1000))
#> # A tibble: 32 × 1
#>      mpg
#>    <dbl>
#>  1  21  
#>  2  21  
#>  3  22.8
#>  4  21.4
#>  5  18.7
#>  6  18.1
#>  7  14.3
#>  8  24.4
#>  9  22.8
#> 10  19.2
#> # … with 22 more rows

Created on 2023-01-12 by the reprex package (v2.0.1)

As the argument is ignored, the result is no different than failing to supply any function at all.
(Supplying the function without naming the argument works as expected.)

Perhaps across should throw a warning when it does not detect an anonymous function being supplied?

Read the original on github.com ↗