nameAlnum: Utility functions, mostly for character manipulation

Description Usage Arguments Value Author(s) See Also Examples

View source: R/nameAlnum.R

Description

Utility functions, mostly for character manipulation.

Usage

1
2
3
4
5
6
pasteDate(..., sep = " ", collapse = NULL, sep.date = sep)
paste0date(..., collapse = NULL)
nameAlnum(x, capitalize=c("asis", "first", "none", "all", "mixed"),
    collapse=" ")
normalizeNames(x, pattern = list(" "), replacement = list("_"),
    alnum = FALSE, ...)

Arguments

x

caharacter.

...

one or more R objects, to be converted to character vectors. For normalizeNames it takes arguments passed to nameAlnum when alnum = TRUE.

sep

a character string to separate the terms.

collapse

an optional character string to separate the results. For nameAlnum it is the separator between the words in the output.

sep.date

a character string to separate the terms from the data itself.

capitalize

character, which letter of each words should be capitalized. "mixed" capitalizes the first letter and case is unchanged for the rest (CamelCase). "first" capitalizes first letter and uses lower case for the rest. Other options are self explanatory.

pattern

a list of character vectors that are replaced. Must match argument replacement.

replacement

a list of character vectors that are the replacements for pattern. Must match argument pattern.

alnum

logical, if nameAlnum should be applied after replacement.

Value

Character vector with desired changes.

Author(s)

Peter Solymos <solymos@ualberta.ca>

See Also

paste, paste0, strsplit, gsub

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
paste0(pasteDate("file", "name", sep="-", sep.date="_"), ".csv")
paste0(paste0date("file", "name", sep.date="_"), ".csv")

data(abmibirds)
x <- data.frame(Name=levels(abmibirds[["Common.Name"]]),
    NameAlnum=nameAlnum(levels(abmibirds[["Common.Name"]])),
    stringsAsFactors = TRUE)
x[grep("'", x$Name),]

data.frame(out=sapply(c("asis", "first", "none", "all", "mixed"),
    function(z) nameAlnum("Olive-sided Flycatcher", z)),
    stringsAsFactors = TRUE)

z <- data.frame(Name=levels(abmibirds[["Common.Name"]]),
    NameNormalized=normalizeNames(levels(abmibirds[["Common.Name"]]),
        pattern=list("'", "-", " "), replacement=list("", "_", "_")),
    stringsAsFactors = TRUE)
z[grepl("'", z$Name) & grepl("-", z$Name),]

mefa4 documentation built on Oct. 7, 2021, 1:06 a.m.