Skip to content

Commit

Permalink
more robust detection of error event
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Cornu committed Nov 29, 2024
1 parent 649d0b5 commit 7523dd1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions R/correctTaxo.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@ correctTaxo <- function(genus, species = NULL, score = 0.5, useCache = FALSE, ve

# split missing taxo in chunks of 30
slices <- split(missingTaxo[, slice := ceiling(.I / BATCH_SIZE)], by = "slice", keep.by = TRUE)


pb <- if(verbose) utils::txtProgressBar(style = 3)

queriedTaxo <- tryCatch(
{
pb <- if(verbose) utils::txtProgressBar(style = 3)
# for each slice of queries
queriedTaxo <- rbindlist(lapply(slices, function(slice) {

Expand Down Expand Up @@ -270,19 +271,20 @@ correctTaxo <- function(genus, species = NULL, score = 0.5, useCache = FALSE, ve
}))
},
error = function(e) {
NA
structure(list(), message = e$message)
},
finally = {
# close progress bar
if(!is.null(pb)) {
close(pb)
pb <- NULL
}
}
)
}

if(is.na(queriedTaxo)) {
warning("There seem to be a problem reaching the TNRS API!", immediate. = TRUE, call. = FALSE)
if(nrow(missingTaxo) && is.null(nrow(queriedTaxo))) {
warning("There seem to be a problem reaching the TNRS API!\n",
attr(queriedTaxo, "message"), immediate. = TRUE, call. = FALSE)
return(invisible(NULL))
}

Expand Down

0 comments on commit 7523dd1

Please sign in to comment.