Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions R/get_gbif_taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ get_gbif_taxonomy <- function(x,
}
}

#clean out higherrank matches, if not allowed
if(!higherrank) {
temp[[i]] <- subset(temp[[i]], matchtype != "HIGHERRANK")
if(nrow(temp[[i]]) == 0) {
warning_i <- paste(warning_i, "No matching species concept!")
}
}

# check for confidence threshold

if(!is.null(conf_threshold) & nrow(temp[[i]]) > 0) {
Expand Down Expand Up @@ -122,7 +130,7 @@ get_gbif_taxonomy <- function(x,

# resolve all synonyms, if allowed

if(!any(temp[[i]]$status == "ACCEPTED") & any(temp[[i]]$status == "SYNONYM")) {
if(nrow(temp[[i]]) > 0 && !any(temp[[i]]$status == "ACCEPTED") & any(temp[[i]]$status == "SYNONYM")) {
if(resolve_synonyms) {
keep <- temp[i]
temp[i] <- taxize::get_gbifid_(temp[[i]]$species[which.max(temp[[i]]$confidence)], messages = verbose)
Expand Down Expand Up @@ -158,7 +166,7 @@ get_gbif_taxonomy <- function(x,

# check for doubtful status

if(all(temp[[i]]$status == "DOUBTFUL")) {
if(nrow(temp[[i]]) > 0 && all(temp[[i]]$status == "DOUBTFUL")) {

temp[[i]] <- subset(temp[[i]], status == "DOUBTFUL")
warning_i <- paste(warning_i, "Mapped concept is labelled 'DOUBTFUL'!")
Expand All @@ -176,7 +184,7 @@ get_gbif_taxonomy <- function(x,

rankorder <- c("kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies")

if(match(temp[[i]]$rank, rankorder) > 7 & !subspecies) {
if(nrow(temp[[i]]) > 0 && match(temp[[i]]$rank, rankorder) > 7 & !subspecies) {

if(length(strsplit(as.character(temp[[i]]$canonicalname), " ")[[1]]) > 2) {

Expand All @@ -193,7 +201,7 @@ get_gbif_taxonomy <- function(x,

}

if(temp[[i]]$matchtype == "HIGHERRANK") {
if(nrow(temp[[i]]) > 0 && temp[[i]]$matchtype == "HIGHERRANK") {
if(higherrank) {
temp[[i]] <- subset(temp[[i]], temp[[i]]$confidence == max(temp[[i]]$confidence))
warning_i <- paste(warning_i, "No matching species concept! Entry has been mapped to higher taxonomic level.")
Expand All @@ -205,7 +213,7 @@ get_gbif_taxonomy <- function(x,


# 4. create structured output
if(temp[[i]]$matchtype != "NONE") {
if(nrow(temp[[i]]) > 0 && temp[[i]]$matchtype != "NONE") {

temp[[i]] <- data.frame(
scientificName = x[i],
Expand Down