An R package to work with the COM(P)ADRE Plant and Animal Matrix Population Databases. Note this package is at an early stage of development, and may contain bugs.

Installation

Install from GitHub with:

To install the development branch use:

remotes::install_github("jonesor/Rcompadre", ref = "devel")

Usage

library(Rcompadre)

Fetching a database

Fetch the most recent database version from compadre-db.org with

compadre <- cdb_fetch("compadre") # or use 'comadre' for the animal database

or load from a local .RData file with, for example:

compadre <- cdb_fetch("path/to/file/COMPADRE_v.4.0.1.RData")

If you prefer using load() to load your local copy of a legacy database, use as_cdb() to convert it to the ‘CompadreDB’ class

load("COMPADRE_v.4.0.1.RData") # loads object 'compadre'
compadre <- as_cdb(compadre)

Subsetting

For the most part CompadreDB objects work like a data frame. They can be subset using [ or subset()

Example analysis: calculating population growth rates

First we’ll use the function cdb_flag to add columns to the database flagging potential issues with the projection matrices, such as missing values, or matrices that don’t meet assumptions like ergodicity, irreducibility, or primitivity.

We’ll only be able to calculate population growth rates from matrices that don’t contain missing values, and we only want to use matrices that meet the assumption of ergodicity, so we’ll subset the database accordingly.

Finally, we’ll use the lambda function from the library popbio to calculate the population growth rate for every matrix in compadre_sub.

library(popbio)
compadre_sub$lambda <- sapply(matA(compadre_sub), lambda)

In the code above, the accessor function matA() is used to extract a list of projection matrices (the full matrix, “matA”) from every row of compadre_sub. There are also accessor functions for the matrix subcomponents (matU(), matF(), matC()), and for many other parts of the database too.

Previous releases

Specific earlier releases of this package can be installed using the appropriate @ tag. You can see details of the existing releases here. Note that the most recent version does not necessarily have an @ tag.

To install version 0.2.0, our last release before our introduction of the new CompadreDB class, and associated major changes to the package:

remotes::install_github("jonesor/Rcompadre@v0.2.0")

Contributions

All contributions are welcome. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.