Seach and retrieve data from the Global Biodiverity Information Facilty (GBIF)
rgbif
is an R package to search and retrieve data from the Global Biodiverity Information Facilty (GBIF). rgbif
wraps R code around the GBIF API to allow you to talk to GBIF from R.
Install from CRAN
Or install the development version from GitHub
Load rgbif
Search by type of record, all observational in this case
Records for Puma concolor with lat/long data (georeferened) only. Note that hasCoordinate
in occ_search()
is the same as georeferenced
in occ_count()
.
All georeferenced records in GBIF
Records from Denmark
Number of records in a particular dataset
All records from 2012
Records for a particular dataset, and only for preserved specimens
Get possible values to be used in taxonomic rank arguments in functions
name_lookup()
does full text search of name usages covering the scientific and vernacular name, the species description, distribution and the entire classification across all name usages of all or some checklists. Results are ordered by relevance as this search usually returns a lot of results.
By default name_lookup()
returns five slots of information: meta, data, facets, hierarchies, and names. hierarchies and names elements are named by their matching GBIF key in the data.frame
in the data slot.
Search for a genus
Search for the class mammalia
Look up the species Helianthus annuus
The function name_usage()
works with lots of different name endpoints in GBIF, listed at http://www.gbif.org/developer/species#nameUsages.
The function name_backbone()
is used to search against the GBIF backbone taxonomy
The function name_suggest()
is optimized for speed, and gives back suggested names based on query parameters.
Get data for a single occurrence. Note that data is returned as a list, with slots for metadata and data.
Get many occurrences. occ_get
is vectorized
Note: The maximum number of records you can get with occ_search()
and occ_data()
is 100,000. See https://www.gbif.org/developer/occurrence
By default occ_search()
returns a dplyr
like output summary in which the data printed expands based on how much data is returned, and the size of your window. You can search by scientific name:
Or to be more precise, you can search for names first, make sure you have the right name, then pass the GBIF key to the occ_search()
function:
key <- name_suggest(q='Helianthus annuus', rank='species')$key[1]
occ_search(taxonKey=key, limit=20)
You can index to different parts of the oupu; here, the metadata:
You can choose what fields to return. This isn’t passed on to the API query to GBIF as they don’t allow that, but we filter out the columns before we give the data back to you.
occ_search(scientificName = "Ursus americanus", fields=c('name','basisOfRecord','protocol'), limit = 20)
Most parameters are vectorized, so you can pass in more than one value:
splist <- c('Cyanocitta stelleri', 'Junco hyemalis', 'Aix sponsa')
keys <- sapply(splist, function(x) name_suggest(x)$key[1], USE.NAMES=FALSE)
occ_search(taxonKey=keys, limit=5)