tidy_rname: Transform char to rname

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/tidy_rname.R

Description

Transform a character vector to another one with good names for data.frames header following several rules.

Usage

1
2
tidy_rname(char, ascii = TRUE, no_dots = TRUE, no_duplicate = TRUE,
  max_size = 16, lowercase = TRUE)

Arguments

char

A character vector with the original columns names.

ascii

Boolean. Only produce ASCII char. Default is TRUE.

no_dots

Boolean. Replace dots by underscores. Default is TRUE.

no_duplicate

Boolean. If there is a duplicate, add a number at the end of the name.

max_size

Integer. Number max of character. If 0, no limits. Will not cut words < of 8 letters. Default is 16. Will keep the first letters and the last ones (a least 3)

lowercase

Boolean. Change to lower cases. Default is TRUE.

Details

The rules applied are :

  1. rules from official doc : use the function make.names

  2. rules of good practice

    • only ASCII character

    • don't use dots because they have a special meaning in R

    • avoid duplicates

    • don't use to long name (less than 16 char).

    • should be only lower cases

Value

A character vector.

Author(s)

Joris Muller

See Also

This function is used by descvars_skeleton to produce the column rname. The base make.names function does a part of the work.

Examples

1
2
3
4
bad_names <- c("white space", "multiples...dots..", "duplicate",
               "duplicate", "$p<c3><a9>cial char", "looooooooognameeeeeeee")
transformed_names <- tidy_rname(bad_names)
transformed_names

jomuller/vartors documentation built on May 19, 2019, 7:26 p.m.