Created
July 8, 2021 10:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example showing usefulness of GBIF API when combined with purrr | |
library(dplyr) | |
library(httr) | |
library(purrr) | |
library(jsonlite) | |
"Trochilidae" %>% # sci name for humming birds | |
paste0("https://api.gbif.org/v1/species/match?name=",.) %>% | |
GET() %>% | |
content() %>% | |
pluck("usageKey") %>% | |
paste0("https://api.gbif.org/v1/species/search/?highertaxon_key=",.,"&limit=1000","&rank=SPECIES") %>% | |
fromJSON() %>% | |
pluck("results") %>% | |
pull(speciesKey) %>% | |
map(~ | |
paste0("https://api.gbif.org/v1/species/",.x,"/vernacularNames") %>% | |
fromJSON() | |
) %>% | |
compact() %>% | |
map(~ .x %>% pluck("results")) %>% | |
bind_rows() %>% | |
select(taxonKey,vernacularName,language) %>% | |
unique() %>% | |
glimpse() # all common names for humming birds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment