clean_names: Create Syntatically Valid Names

Description Usage Arguments Details Value Examples

Description

A wrapper for the make.names() function to make syntatically valid names using my preferred syntax.

Usage

1

Arguments

df

Any object with a name, but I typically use them for data frames, hence "df".

Details

Replaces spaces with underscore

Sets all letters to lower case

Injects an "x" before a syntatically invalid beginning (e.g. a number, or symbol)

Indicates duplicate names with a "_n", where n is the nth duplicate

Value

Returns the object you fed it with changed names.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Using a data.frame
df <- data.frame("Happy Boy" = c(1:10),
                "3BeeSoup    " = c(letters[1:10]),
                "Happy Boy" = c(10:1))

clean_names(df)

# Using a tibble
df2 <- dplyr::tibble(`Happy Boy` = c(1:10),
                      `3BeeSoup    ` = c(letters[1:10]))

clean_names(df2)

christian-million/researchR documentation built on May 15, 2019, 12:45 p.m.