Skip to content

treatment by rename_at() of function with no argument not covered in documentation #5545

@david-romano

Description

@david-romano

In the documentation for select_all() (and related commands), the .funs argument is described as follows:

.funs | A function fun, a purrr style lambda ~ fun(.) or a list of either form.

If the value passed to .funs is a 0-ary function that returns a character vector of the right length, this vector is used to rename columns according to (relative) column index:

library(tidyverse)
mpg %>% 
  rename_at(2:3, ~ letters[1:2])
#> # A tibble: 234 x 11
#>    manufacturer a            b  year   cyl trans   drv     cty   hwy fl    class
#>    <chr>        <chr>    <dbl> <int> <int> <chr>   <chr> <int> <int> <chr> <chr>
#>  1 audi         a4         1.8  1999     4 auto(l… f        18    29 p     comp…

In other words, in this case the value passed to .funs is not treated as a function, which instead would assign the entire character vector as the name of every column. A mention of this special case in the documentation would be helpful.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions