Project | Main branch | Devel branch |
---|---|---|
An R package to facilitate working with the COM(P)ADRE Plant and Animal Matrix Population Databases.
Install the stable release package from CRAN with:
install.packages("Rcompadre")
Install the package from GitHub with:
# install package 'remotes' if necessary
# will already be installed if 'devtools' is installed
install.packages("remotes")
# argument 'build_opts = NULL' only needed if you want to build vignettes
::install_github("jonesor/Rcompadre", build_opts = NULL) remotes
To install from the development branch use:
::install_github("jonesor/Rcompadre", ref = "devel") remotes
library(Rcompadre)
Fetch the most recent database version from compadre-db.org with
<- cdb_fetch("compadre") # or use 'comadre' for the animal database compadre
or load from a local .RData
file with
<- cdb_fetch("path/to/file/COMPADRE_v.4.0.1.RData") compadre
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'
<- as_cdb(compadre) compadre
For the most part CompadreDB
objects work like a data
frame. They can be subset using [
, subset()
or
filter()
# subset to the first 10 rows
1:10, ]
compadre[
# subset to the species 'Echinacea angustifolia'
subset(compadre, SpeciesAccepted == "Echinacea angustifolia")
# subset to the species 'Echinacea angustifolia'
filter(compadre, SpeciesAccepted == "Echinacea angustifolia")
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.
<- cdb_flag(compadre) compadre_flags
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.
<- subset(
compadre_sub
compadre_flags,== FALSE & check_ergodic == TRUE
check_NA_A )
Finally, we’ll use the eigs()
function from the popdemo package to
calculate the population growth rate for every matrix in
compadre_sub
.
$lambda <- sapply(matA(compadre_sub), popdemo::eigs, what = "lambda") compadre_sub
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.
Specific earlier releases of this package can be installed using the
appropriate @
tag.
For example to install version 0.1.0:
::install_github("jonesor/Rcompadre@v0.1.0") remotes
See the Changelog for more details.
Jones, Owen R., Patrick Barks, Iain M. Stott, Tamora D. James, Sam C. Levin, William K. Petry, Pol Capdevila, et al. 2022. “Rcompadre and Rage – Two R Packages to Facilitate the Use of the COMPADRE and COMADRE Databases and Calculation of Life History Traits from Matrix Population Models.” Methods in Ecology and Evolution. doi: 10.1111/2041-210X.13792.
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.
There are numerous ways of contributing.
You can submit bug reports, suggestions etc. by opening an issue.
You can copy or fork the repository, make your own code edits and then send us a pull request. Here’s how to do that.
You can get to know us and join as a collaborator on the main repository.
You are also welcome to email us.