Skip to contents

Clean column names by replacing all spaces and punctuation with a single underscore

Usage

clean_colnames(x, lowercase = FALSE, uppercase = FALSE, titlecase = FALSE)

Arguments

x

Character vector OR any object with colnames() method, like matrix, data.frame, data.table, tibble, etc.

lowercase

Logical: If TRUE, convert to lowercase.

uppercase

Logical: If TRUE, convert to uppercase.

titlecase

Logical: If TRUE, convert to Title Case.

Value

Character vector with cleaned names.

Author

EDG

Examples

clean_colnames(iris, lowercase = FALSE, uppercase = FALSE, titlecase = FALSE)
#> [1] "Sepal_Length" "Sepal_Width"  "Petal_Length" "Petal_Width"  "Species"