Last active
December 25, 2015 11:49
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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