Apply a list of functions to a biomonitoR object

Sometimes it can be useful to apply a list of functions to a biomonitoR object. For example with a properly setted list of functions you can calculate more indices at once.


macro <- read.csv(url(""))

macro.asb <- asBiomonitor(macro)

macro.agg <- aggregatoR(macro.asb)

# creating a list of functions funs

myshan <- function(x)(shannon(x))

mybmwpi <- function(x)(bmwp(x, method = "i"))

mybmwpb <- function(x)(bmwp(x, method = "b"))

funs <- list(shannon = myshan, ibmwp = mybmwpi, bmwp = mybmwpb)

# apply the list of functions on macro.agg

indices <- lapply(funs, function(f) f(macro.agg))

# transform the list indices into a data.frame, indices)

Manage species groups in biomonitoR

Sometimes happens to have species groups in your data (e.g Rhyacophila nubila/obliterata). To overcome this issue you can import your data and putting the problematic species in the user’ custom database (and of course in the Taxa column of the database to analyse). Then you have to move to R where you must replace the slash (as in our example) with a space from both the database to analyse and from the custom database. This should assure that your species groups will be recognised by asBiomonitor.


# use gsub to replace slash with space 
# (macro is the database to analyze and user_db 
# the custom database to add to the reference database)
# for example we want to change species groups like
# Rhyacophila nubila/obliterata to Rhyacophila nubila obliterata

macro$Taxa <- gsub("/", "_", macro$Taxa, fixed = T)
user_db$Taxa <- gsub("/", "_", user_Db$Taxa, fixed = T)
user_db$Species <- gsub("/", "_", user_db$Species, fixed = T)

macro.asb <- asBiomonitor(macro, dfref = user_db, overwrite = F)


Reference database

Reference database is a modified version of the database of and is structured as follow:

Column Taxa must contain unique elements, in other words you can not have the same name repeated twice or more. You can add missing taxa by using the same structure of the reference database and by specifying it in the dfref option:


# macro is the data.frame provided by the user

macro.asb <- asBiomonitor(macro, dfref = user_db, overwrite = F)


You must assure that the taxa you add are not already present in the default database.
Alternatively you can replace the default database with your custom database, specifying it in the overwrite option:


macro.asb <- asBiomonitor(macro, dfref = user_db, overwrite = T)


The possibility to use your own reference database is very important. As an example, if you want to correctly calculate Iberian ASPT (IASPT) you have to provide a modified version of the database (ask us for this database). This is because biomonitoR consider Ancylus and Ferrissia as Planorbidae while the IASPT consider them as belonging to the families Ancylidae and Ferrissidae, respectively.

You must assure that the custom database contains all the names of the taxa that you want anaylize with biomonitoR. WARNING!!! The current version of biomonitoR does not support uncertain classification of taxa (e.g Rhyacophila nubila/obliterata) but see this post for a workaround.


The function asBiomonitor is the core of the package biomonitoR. The default settings allows the user to compare and merge his dataset to the database taken from Compare means that the taxa list of the user’s data.frame is compared with that of reference database, after that the two are merged.


macro.asb <- asBiomonitor(macro, dfref = NULL, overwrite = F)


where macro is the user’s data.frame. This data.frame must have a column named “Taxa” where put species, genus, family, etc. names and one or more columns of samples.
When user’s taxa list contains spelling errors asBiomonitor provides suggestions to correct the wrong name if a similar name exists in the reference database. If suggestions are not provided the user has to exit from the script by pressing esc on the keyboard. This behaviour is required to assure compatibility between user data.frame and reference database. To overcome this issue the user can provide is own reference database in order to modify or replace the existing reference database.

Add custom reference data.frame to the default reference database.

macro.asb <- asBiomonitor(macro, dfref = user_db, overwrite = F)


Replace the default reference database with the custom database.

macro.asb <- asBiomonitor(macro, dfref = user_db, overwrite = T)


The structure of the custom data.frame is the topic of this post.