Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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