rgbif

An interface to the GBIF API for the R statistical programming environment

rgbif homepage
rgbif-bg

rgbif is an R package from rOpenSci that allows searching and retrieving data from GBIF. rgbif wraps R code around the GBIF API to allow you to talk to GBIF from R and access metadata, species names, and occurrences.

Installing the package in R is simple:

> install.packages("rgbif")

Once installed, rgbif allows you to easily

  • get data for single occurrences
  • retrieve multiple occurences
  • search for taxon names
  • generate maps of occurences

Full functionality is described in the rgbif tutorial.  The rgbif package is also part of the SPOCC Species Occurrence Data suite, that provides access to occurrence records from multiple databases.

Citing data retrieved via rgbif

Note: GBIF recommends using a derived dataset for citing data obtained using synchronous API calls as used by rgbif in occ_data() and occ_search().

For data obtained using the occ_download() routes, gbif_citation() can be used to retrieve the DOI.

The rgbif library includes a function, gbif_citation(), that will help you properly cite the data downloaded from GBIF. To use, simply pass either a single occurrence key, a dataset key, or the results of a call to the occ_download_get functions.

Examples:

Write CSV file containing summary of datasets to use with the Derived Dataset tool
> myData<-occ_data(taxonKey=10709636)
> datasetCounts<-myData$data %>% count(datasetKey, sort=TRUE) 
> write.table(datasetCounts, "~/derivedDatasetCounts.txt",col.names=FALSE, row.names=FALSE,sep=",")
Get citation for a single occurrence, passing the occurrence key as an argument
> gbif_citation(x=1265576727)
<<rgbif citation>>
   Citation: iNaturalist.org (2017). iNaturalist Research-grade Observations.
        Occurrence Dataset https://doi.org/10.15468/ab3s5x accessed via
        GBIF.org on 2017-10-25.. Accessed from R via rgbif
        (https://github.com/ropensci/rgbif) on 2017-10-25
   Rights:
Get citation for a dataset, passing the dataset key as an argument
> gbif_citation(x='d52d01f6-7472-4dbf-9ea8-a33c343255ac')
<<rgbif citation>>
   Citation: Moeslund J E (2016). Vegetation data from protected areas in
        Denmark (§ 3 in the Danish Nature Protection Act). Version 8.1.
        Department of Bioscience, Aarhus University. Occurrence Dataset
        https://doi.org/10.15468/ar7pbr accessed via GBIF.org on 2017-10-25..
        Accessed from R via rgbif (https://github.com/ropensci/rgbif) on
        2017-10-25
   Rights:
Get citation for asynchronous downloads, passing the results of a call to the occ_download_get function:
> my_download<-occ_download_get("0005737-171002173027117",overwrite=TRUE)
Download file size: 0.26 MB
On disk at /tmp/0005737-171002173027117.zip
> gbif_citation(my_download)
$download
[1] "GBIF Occurrence Download https://doi.org/10.15468/dl.j0ehrr Accessed from R via rgbif (https://github.com/ropensci/rgbif) on 2017-10-18"

...

This response will also include individual citations of contributing datasets, however, the above citation containing the DOI will include references to each of these including information about which specific occurrences were included in the download.

Get citation for downloads, passing the results of a call to the occ_download_meta function:
> my_download_metadata<-occ_download_meta("0005737-171002173027117")
> gbif_citation(my_download_metadata)
$download
[1] "GBIF Occurrence Download https://doi.org/10.15468/dl.j0ehrr Accessed from R via rgbif (https://github.com/ropensci/rgbif) on 2017-10-18"
...

Scott Chamberlain (2017). rgbif: Interface to the Global 'Biodiversity' Information Facility 'API'. R package version 0.9.8. https://CRAN.R-project.org/package=rgbif