Skip to contents

Rename every column of a dataframe with its label

Usage

rename_with_labels(df, except = NULL)

Source

https://stackoverflow.com/q/75848408/3888000

Arguments

df

a data.frame

except

<tidy-select> columns that should not be renamed.

Value

A dataframe which names are copied from the label attribute

Author

Dan Chaltiel

Examples

rename_with_labels(mtcars2[,1:5], except=5) %>% names()
#> [1] "Model"                 "Miles/(US) gallon"     "Number of cylinders"  
#> [4] "Displacement (cu.in.)" "hp"                   
rename_with_labels(iris2, except=Sepal.Length) %>% names()
#> [1] "Sepal.Length"    "Width of Sepal"  "Length of Petal" "Width of Petal" 
#> [5] "Specie"         
rename_with_labels(iris2, except=starts_with("Pet")) %>% names()
#> [1] "Length of Sepal" "Width of Sepal"  "Petal.Length"    "Petal.Width"    
#> [5] "Specie"