Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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