make.names
Make Character Strings into Legal Names

### Description

Makes character strings into legal names.

### Usage

    make.names(names, unique = FALSE, allow_ = TRUE)

### Arguments

names | a character vector.
unique | a logical flag. TRUE if the resulting set of names should be unique; otherwise, FALSE (the default).
allow_ | a logical flag. TRUE (the default) if the underscore character is allowed to appear in names. If FALSE, the underscore character is converted to a period, like other non-name characters.

### Details

The algorithm does the following:

1. Adds the character "X" to the beginning of any string that does not start with a letter or a period (".").
2. Replaces each illegal character with ".".
3. Changes any names that are reserved names (such as "for", "function", and so on to non-reserved names by adding "." to the end.
4. If unique is TRUE, duplicate names are made unique by adding ".<number>" as required.

Value
returns a character vector, each element of which is syntactically a legal name (that is, made up of letters, numbers, and "."). A legal name must not begin with a number. If allow_ is TRUE, then the underscore character is also allowed to appear in a name.
Examples

    make.names(c("abc","ab??","1abc", ""))
    # [1] "abc"   "ab.."  "X1abc" "X"
    make.names(rep("A",5))
    # [1] "A" "A" "A" "A" "A"
    make.names(rep("A",5), unique=TRUE)
    # [1] "A"   "A.1" "A.2" "A.3" "A.4"
    make.names(c(rep("A",5), "A.3"), unique=TRUE)
    # [1] "A"   "A.1" "A.2" "A.4" "A.5" "A.3"
    #  note that the fourth element becomes "A.4",
    #  since "A.3" already exists
    make.names(rep("",5), unique=TRUE)
    # [1] "X"   "X.1" "X.2" "X.3" "X.4"
    make.names(c("_A","A_","_"))
    # [1] "X_A" "A_"  "X_"
    make.names(c("_A","A_","_"), allow_=FALSE)
    # [1] "X.A" "A."  "X."
    make.names(c("for", "function"))
    # [1] "for."      "function."

Package base version 6.1.5-18
Package Index