Make Character Strings Unique

DESCRIPTION:

Makes all elements of a character vector be unique by appending sequence numbers to duplicates.

USAGE:

make.unique(names, sep=".")

REQUIRED ARGUMENTS:

names
a vector of character strings

OPTIONAL ARGUMENTS:

sep
a character string used as a separator between a duplicate string and the appended sequence number. The default is ".".

VALUE:

A character vector having the same length as names and containing unique strings.

DETAILS:

This function emulates the R function make.unique. It is used by functions in the pkgutils library.

If character vector A is already unique, then make.unique(c(A, B)) preserves A.

This version is probably not fast enough to make unique row names for large data frames.

SEE ALSO:

EXAMPLES:

make.unique(c("a", "a", "a", "a"))
#  "a"   "a.1" "a.2" "a.3"
make.unique(c("a", "a", "a", "a.1"))
#  "a"   "a.2" "a.3" "a.1"
make.unique(c(make.unique(c("a", "a", "a")), "a"))
#  "a"   "a.1" "a.2" "a.3"

# unique vector A is not changed
A <- c("a","b","c")
B <- c("b","c","d")
make.unique(c(A,B))
#  "a"   "b"   "c"   "b.1" "c.1" "d"