tprSpeciesCode {TapeS} | R Documentation |
Get BDAT species code or transform it to a name.
Description
Function to get BDAT species code, or transform it to a german or english name, possibly an abbreviated version or even a scientific name
Usage
tprSpeciesCode(inSp = NULL, outSp = NULL)
Arguments
inSp |
species information given, either numeric or character |
outSp |
character vector of names, for which information should be returned |
Details
The function matches inSp to outSp. Depending on inSp, being either a numeric vector of values between 1 and 36 or a character vector of species names. Possible names are those which could be return values. One can get all names and the respective species code by calling the function with inSP=NULL and outSP=NULL (the default).
English species names and codes are taken from https://www.forestry.gov.uk/pdf/PF2011_Tree_Species.pdf/$FILE/PF2011_Tree_Species.pdf while slightly adjusting the codes to be unique compared to the german codes (e.g. European larch is now ELA instead of EL).
Any given species code outside the interval [1, 36] is given the code 1 (i.e. Norway spruce), while throwing a warning. If any inSp - name is invalid, i.e. not in species list, this throws an error.
All elements of outSp, which are not colnames of the default returned data.frame, are silently dropped.
Value
vector or data.frame, depending on length of 'outSp'.
Examples
tprSpeciesCode(inSp=NULL, outSp=NULL) ## the default
tprSpeciesCode() ## the same
tprSpeciesCode(outSp = "scientific")
tprSpeciesCode(inSp = c(1, 2)) ## giving codes
tprSpeciesCode(inSp = c(1, 2, -1, 37)) ## values outside [1, 36] are given code 1
tprSpeciesCode(inSp = c(1, 2), outSp = c("scientific")) ## output a vector
tprSpeciesCode(inSp = c("Bu", "Fi")) ## asking for codes of abbreviated german names
tprSpeciesCode(inSp = c("Bu", "Fi", "Bu")) ## order is preserved
tprSpeciesCode(inSp = c("Buche", "Fichte")) ## asking for codes of german names
tprSpeciesCode(inSp = c("BE", "NS")) ## ... abbreviated english names
tprSpeciesCode(inSp = c("beech", "Norway spruce")) ## ... english names
tprSpeciesCode(inSp = c("Fagus sylvatica", "Picea abies")) ### ... scientific names
## not run
## tprSpeciesCode(inSp = c("Fagus sylvatica", "Picea")) ## error, 2nd name wrong
## end not run