Created
July 8, 2021 10:12
-
-
Save jhnwllr/0c10feb4be1c64cfec81f92a1047fddd to your computer and use it in GitHub Desktop.
This file contains 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