Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Last active December 25, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbaums/6971353 to your computer and use it in GitHub Desktop.
Save johnbaums/6971353 to your computer and use it in GitHub Desktop.
Parse taxon names from R, using the GBIF name parser API (http://portaldev.gbif.org/developer/species).
gbif_parse <- function(x) {
# x is a vector of species names
library(RJSONIO)
library(RCurl)
library(plyr)
u <- "http://api.gbif.org/v1/parser/name"
res <- fromJSON(
postForm(u,
.opts = list(postfields = RJSONIO::toJSON(x),
httpheader = c('Content-Type' = 'application/json')))
)
do.call(rbind.fill, lapply(res, as.data.frame))
}
library(devtools)
source_url('https://gist.github.com/johnbaums/6971353/raw/gbif_parse.R')
# Examples
gbif_parse('x Agropogon littoralis')
gbif_parse(c("Hovenia dulcis", "Mauryanda barclaiana", "Senecio glastifolius",
"Carex buxbaumii", "Alternanthera philoxeroides", "Catapodium marinum",
"Secale cereale subsp. cereale", "Verbena supina var. erecta",
"Carica papaya", "Impatiens walleriana", "Pennisetum villosum",
"Lolium X hybridum", "Hedera helix", "Arrhenatherum elatius var. elatius",
"Buddleja lindleyana", "Fallopia sachalinensis", "Trifolium alexandrinum",
"Acanthus spinosus", "Impatiens balsamina", "Crassula spathulata"))
spp <- read.delim('http://gbif-ecat.googlecode.com/svn/trunk/ecat-common/src/test/resources/scientific_names.txt',
header=TRUE, sep='\t', comment.char='#', stringsAsFactors=FALSE,
fileEncoding='utf-8')
spp.parsed <- gbif_parse(spp$scientificName)
head(spp.parsed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment