Skip to content

Instantly share code, notes, and snippets.

@damianooldoni
Last active January 18, 2021 08:28
Show Gist options
  • Save damianooldoni/2b1e264fb412ff3b881c99a4bc63cb22 to your computer and use it in GitHub Desktop.
Save damianooldoni/2b1e264fb412ff3b881c99a4bc63cb22 to your computer and use it in GitHub Desktop.
Given a vector of scientific names, retrieve the full scientific name with authority from GBIF Backbone. Used for checking taxa in official annexes of BIM.
library(rgbif)
library(inborutils)
library(tidyverse)
# names list example
names_bim <- c("Asplenium hemionitis L.",
"Dracaena draco (L.) L.",
"Viola rupestris subsp. relicta Jalas")
# make a df of it
names_bim_df <- tibble(name = names_bim)
# use gbif_species_match function from inborutils package
gbif_match <-
gbif_species_name_match(names_bim_df, strict = TRUE)
# retrieve canonicalName and authorship by applying name_usage for all taxa
gbif_info_df <-
map_dfr(gbif_match$usageKey, function(x) {
if (!is.na(x)) {
name_usage(key = x)$data %>%
select(canonicalName, authorship)}
else {tibble(canonicalName = NA_character_, authorship = NA_character_)}
})
# paste canonicalName and authorship together
gbif_info_df <-
gbif_info_df %>%
mutate(complete_name = paste(canonicalName, authorship)) %>%
select(complete_name)
# save names
write_csv(gbif_info_df, file = "gbif_full_name.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment