Skip to content

Instantly share code, notes, and snippets.

@jhpoelen
Last active August 29, 2015 14:20
Show Gist options
  • Save jhpoelen/ddfcc59249449df01399 to your computer and use it in GitHub Desktop.
Save jhpoelen/ddfcc59249449df01399 to your computer and use it in GitHub Desktop.
Example of how to use GBIF to generate a species list for a specific are and use GloBI to retrieve interactions for those species. Please refer to http://ropensci.org to learn more about the packages.
# install rgbif and rglobi libraries (see http://ropensci.org for more info)
install.packages(c('rgbif', 'rglobi'))
# define geometric bounding box (around california)
geo1 <- "POLYGON((-126 32, -114 32, -114 41, -126 41, -126 32))"
# retrieve a bunch of occurrences of Mustelidae with the geometric area
mustelidaeOcc <- rgbif::occ_search(scientificName='Mustelidae', fields='minimal', geometry = geo1)$data
# get any interactions records involving unique taxa occurrences at bbox geo1
interacts <- rglobi::get_interactions_by_taxa(unique(mustelidaeOcc$name))
# list interaction columns
names(interacts)
# [1] "source_taxon_external_id" "source_taxon_name"
# [3] "source_taxon_path" "source_specimen_life_stage"
# [5] "interaction_type" "target_taxon_external_id"
# [7] "target_taxon_name" "target_taxon_path"
# [9] "target_specimen_life_stage" "latitude"
# [11] "longitude" "study_title"
# number of available interaction records
count(interacts)
# 591
# print first six target taxon names
head(interacts$target_taxon_name)
# [1] "Orconectes propinquus" "Crustacea" "Canis lupus familiaris"
# [4] "Actitis macularius" "Crocodylus acutus" "Larus californicus"
# print first six unique source taxon names
head(interacts$source_taxon_name)
# [1] "Lontra canadensis" "Enhydra lutris nereis" "Enhydra lutris"
# [4] "Taxidea taxus" "Neovison vison" "Mustela frenata"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment