Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhnwllr/0c10feb4be1c64cfec81f92a1047fddd to your computer and use it in GitHub Desktop.
Save jhnwllr/0c10feb4be1c64cfec81f92a1047fddd to your computer and use it in GitHub Desktop.
# 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