Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter higherrank results if not allowed #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions R/get_gbif_taxonomy.R
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