Skip to content

Instantly share code, notes, and snippets.

@PhillRob
Last active September 24, 2015 06:58
Show Gist options
  • Save PhillRob/f7a32a8dbea18608004e to your computer and use it in GitHub Desktop.
Save PhillRob/f7a32a8dbea18608004e to your computer and use it in GitHub Desktop.
returns the first 8 trait values for any given species in EOL relying on the reol, traints and dplyr packages.
get.eol.trait <- function(sp,trait)
{
if (length(trait)==0)
{
print("need trait")
stop()
}
library("reol"); library("traits"); library("dplyr")
pages<-DownloadSearchedTaxa(sp, to.file=F, MyKey=NULL, verbose=TRUE)
pages1<-as.numeric(gsub("eol","",colnames(as.data.frame(pages))))
if (length(pages1)==0)
{
return("NA")
}
else
{
oid1<-traitbank(pages1)
oid2<-as.data.frame(oid1[2])
oid3<-oid2[(oid2$graph.dwc.measurementtype.rdfs.label.en==trait)&!is.na(oid2$graph.dwc.measurementvalue),]
oid4<-data.frame
oid4<-c(oid3$graph.scientific.name[1],oid3$graph.dwc.measurementtype.rdfs.label.en[1],oid3$graph.dwc.measurementvalue[1:8])
return(oid4)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment