From e4e179e02637bfb7f2740306aeaf9690d58faf5a Mon Sep 17 00:00:00 2001 From: Will Gearty Date: Tue, 5 Nov 2019 11:09:50 -0600 Subject: [PATCH 1/2] Filter higherrank results --- R/get_gbif_taxonomy.R | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/R/get_gbif_taxonomy.R b/R/get_gbif_taxonomy.R index feccb5c..b24a935 100644 --- a/R/get_gbif_taxonomy.R +++ b/R/get_gbif_taxonomy.R @@ -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) { @@ -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'!") @@ -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) { @@ -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.") @@ -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], From 8a9bb4e09475b962081cad9b08bb4fc32482d80e Mon Sep 17 00:00:00 2001 From: Will Gearty Date: Tue, 5 Nov 2019 12:03:43 -0600 Subject: [PATCH 2/2] Another if check --- R/get_gbif_taxonomy.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_gbif_taxonomy.R b/R/get_gbif_taxonomy.R index b24a935..e3ffdb1 100644 --- a/R/get_gbif_taxonomy.R +++ b/R/get_gbif_taxonomy.R @@ -130,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)