format_names: Format names and values

Description Usage Arguments Examples

View source: R/format_names.R

Description

This function can be used on any data.frame, list or character vector to format their names or values. It supports snake case and camel case.

Usage

1
2
3
4
5
6
7
8
format_names(
  x,
  ...,
  snake_case = FALSE,
  camelCase = FALSE,
  tolower = FALSE,
  toupper = FALSE
)

Arguments

x

a data.frame, list or character vector

...

when x is a data.frame: new column names to set, which can be named (in the form old = "new"). The original column names do not need to be quoted, see Examples.

snake_case

logical to indicate whether the column names must be in snake case. This will have no effect on manually set column names.

camelCase

logical to indicate whether the column names must be in camel case. This will have no effect on manually set column names.

tolower, toupper

logical to indicate whether the column names must be lower/upper case. This will have no effect on manually set column names.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
df <- data.frame(Name.341ABC = "value", 
                 name_123def = "value",
                 This.is.a.column = "value")
                 
format_names(df, snake_case = TRUE)

format_names(df, camelCase = TRUE)

format_names(df, letters[1:3])

format_names(df, This.is.a.column = "a_new_colname")

rownames(mtcars) <- format_names(rownames(mtcars), snake_case = TRUE)
mtcars[, 1:5]

format_names(list(a = 1, b = 2), c("new_1", "new_2"))

## Not run: 
library(dplyr)
starwars %>%
  format_names(camelCase = TRUE) %>%        # new column names
  mutate(name = name %>% 
           format_names(name, 
                        snake_case = TRUE)) # new values in column

## End(Not run)

cleaner documentation built on June 13, 2021, 5:06 p.m.