Learn R Programming

fuzzySim (version 2.0)

spCodes: Obtain unique abbreviations of species names

Description

This function takes a vector of species names and converts them to abbreviated species codes containing the specified numbers of characters from the genus, the specific and optionally also the subspecific name. Separators can be specified by the user. The function checks that the resulting codes are unique.

Usage

spCodes(species, nchar.gen = 3, nchar.sp = 3, nchar.ssp = 0, 
sep.species = " ", sep.spcode = "")

Arguments

species

a character vector containig the species names to be abbreviated.

nchar.gen

the number of characters from the genus name to be included in the resulting species code.

nchar.sp

the number of characters from the specific name to be included in the resulting species code.

nchar.ssp

optionally, the number of characters from the subspecific name to be included in the resulting species code. Set it to 0 if you have subspecific names in species but do not want them included in the resulting species codes.

sep.species

the character that separates genus, specific and subspecific names in species. The default is a white space.

sep.spcode

the character you want separating genus and species abbreviations in the resulting species codes. The default is an empty character (no separator).

Value

This function returns a character vector containing the species codes resulting from the abbreviation. If the numbers of characters specified do not make for unique codes, an error message is displayed showing which species names caused it, so that you can try again with different nchar.gen, nchar.sp and/or nchar.ssp.

See Also

substr, strsplit

Examples

Run this code
# NOT RUN {
data(rotifers)

head(rotifers)

## add a column to 'rotifers' with shorter versions of the species names:

# }
# NOT RUN {
rotifers$spcode <- spCodes(rotifers$species, sep.species = "_", 
nchar.gen = 1, nchar.sp = 4, nchar.ssp = 0, sep.spcode = ".")

# this produces an error due to resulting species codes not being unique
# }
# NOT RUN {
rotifers$spcode <- spCodes(rotifers$species, sep.species = "_", 
nchar.gen = 1, nchar.sp = 5, nchar.ssp = 0, sep.spcode = ".")

# with a larger number of characters from the specific name,
# resulting codes are now unique

## check out the result:
head(rotifers)
# }

Run the code above in your browser using DataLab