Skip to content
Create a gist now

Instantly share code, notes, and snippets.

This function check which species (both plants and animals) are considered "invaders" somewhere in the world.
#This function check which species (both plants and animals) are considered "invaders" somewhere in the
# world. For that end, it checks GISD ( and returns a value, either
#"Not invasive" or the brief description presented in GISD. Note that the webpage contains more
#information. Also note that the function won't tell you if it's exotic in your area, a lot of exotic
#species are not considered invaders (yet). As expected, the function is as good as the database is, which
#I find quite reliable and well maintained. The database is also able to recognize a lot (but not all) of
#the species synonyms. This function worked for me, but I didn't test it intensively, and any changes on
#the webpage html design will return wrong values. Apply the usual disclaimers when using it.
#The function is slow (not optimized at all), so be patient with long lists of species.
#Author Ignasi Bartomeus ( Last updated 23 Nov 2012.
is.invasive(sp, simplified.df = FALSE)
#sp: a vector of species names in latin (Genus species)
#simplified.df: Returns a data.frame with the species name and the values "Invasive", "Not Invasive". I
#recomend to check first the not simplified version (default), which contains raw information about the
#level of invasiveness.
#The function:
is.invasive <- function(sp, simplified.df = FALSE){
#reformat sp list
species <- gsub(" ","+",sp)
#create urls to parse
urls <- paste("",
species,"&rn=&hci=-1&ei=-1&lang=EN", sep = "")
#create a data.frame to store the Output
Out <- data.frame(species = sp, status = c(1:length(urls)))
#loop through all species
for(i in 1:length(urls)){
#Parse url and extract table
doc <- htmlTreeParse(urls[i], useInternalNodes = TRUE)
tables <- getNodeSet(doc, "//table")
t <- readHTMLTable(tables[[4]])
tt <- as.matrix(t)
if(length(grep("No invasive species currently recorded",tt, value = TRUE)) > 0){
Out[i,2] <- "Not invasive"
if(simplified.df == FALSE){Out[i,2] <- tt[12,1]}
else{Out[i,2] <- "Invasive"}
print(paste("Checking species", i+1))
sp <- c("Carpobrotus edulis", "Rosmarinus officinalis")
## first species is invasive, second one is not.
d <- is.invasive(sp)
d <- is.invasive(sp, simplified.df = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.