The problem occurs when I utilize the occ_search() and occ_download() functions from rgbif package. However, the error is not consistently reproducible, making it difficult to pinpoint the exact cause.
To provide some context, I'm running the occ_search() function within a loop that iterates through a species list for a specific country. The loop is designed to gather occurrence data for each species as the example below for reference
species<- c("Abietinella abietina",
"Acaulon casasianum",
"Acaulon dertosense",
"Acaulon fontiquerianum",
"Acaulon mediterraneum")
DK <- c(1, 0, 0, 0, 0)
FO <- c(0, 0, 0, 0, 0)
FI <- c(1, 0, 0, 0, 0)
IS <- c(1, 0, 0, 0, 0)
NO <- c(1, 0, 0, 0, 1)
moss_occ <- data.frame(species, DK, FO, FI, IS, NO)
species_occurrences<- list()
for (i in 2:6) {
country <-colnames(moss_occ)[i]
occurrence <- occ_search(scientificName = moss_occ$species[which(moss_occ[[i]] == 1)], hasCoordinate = TRUE,
country = colnames(moss_occ)[[i]], limit = 300)
species_occurrences[[i]] <- occurrence
This works fine, but when I try to run it with longer species list I find the error:
Error in curl::curl_fetch_memory(x$url$url, handle = x$url$handle) : HTTP/2 stream was not closed cleanly before end of the underlying stream
While on most cases with smaller dataset it works, I've experienced the same error even with one species. Connectivity could have been a potential concern, but the error happens even when I am connected to a stable internet connection.
At this point, I'm fairly sure that the issue is on my side, but I dont know how to identify and correct it, and other posts on similar issues were no help.
Any ideas or suggestion on what might be causing it and how to adress it would be welcome. Thanks
Session info:
R version 4.3.0 (2023-04-21)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 purrr_1.0.1 readr_2.1.4
[7] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0 rgbif_3.7.7