-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_AFDsynonyms.R
63 lines (49 loc) · 1.77 KB
/
get_AFDsynonyms.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#' Get synonyms for species names from AFD checklist
#'
#' @author Payal Bal
#'
#' @param species Scientific name of species, can inlcude subspecies
#' @param checklist AFD taxonomic cheklist
#' @return list
#'
#' @examples
# test <- ...
get_AFDsynonyms <- function(species, checklist) {
## Define output object
out <- list()
for (i in species) {
message("Looking for ", i, "in AFD checklist...")
## Look for entire name in synonyms
z <- checklist[grep(i, checklist$SYNONYMS)]$SYNONYMS
if(length(z)==0){
message("Not found in AFD checklist")
fullname_synonyms <- NA
} else{
message("****** Full name found in AFD checklist *******")
fullname_synonyms <- paste(z, sep="", collapse="; ")
}
## Look at synonyms for genus only
x <- grep(word(i,-1), checklist[grep(word(i,1), checklist$VALID_NAME)]$SYNONYMS, value = TRUE)
if (length(x) == 0) {
message(cat("Genus", word(i,1), "not found in AFD synonyms"))
genus_synonyms <- NA
} else {
message(cat("Genus", word(i,1), "found in AFD synonyms *******"))
genus_synonyms <- paste(x, sep="", collapse="; ")
}
## Look at synonyms for species only
y <- grep(word(i,1), checklist[grep(word(i,-1), checklist$SYNONYMS)]$SYNONYMS, value = TRUE)
if (length(y) == 0) {
message(cat("Species", word(i,-1), "not found in AFD synonyms"))
species_synonyms <- NA
} else {
message(cat("Species", word(i,-1), "found in AFD synonyms *******"))
species_synonyms <- paste(y, sep="", collapse="; ")
}
temp <- list(fullname_synonyms = fullname_synonyms,
genus_synonyms = genus_synonyms,
species_synonyms = species_synonyms)
out[[i]] <- temp
}
return(out)
}