-
Notifications
You must be signed in to change notification settings - Fork 11
/
README.Rmd
154 lines (100 loc) · 5.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
eval = TRUE
)
```
# Rcompadre <img src="man/figures/logo_rcompadre.png" alt="rcompadre logo" align="right" height="160" style="float:right; height:160px;">
<!--- Continuous integration badges --->
<!--- BE CAREFUL WITH THE FORMATTING --->
| Project | Main branch | Devel branch |
|---------|:------------|:--------------|
| [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.html) | [![R-CMD-check](https://github.com/jonesor/Rcompadre/actions/workflows/main_check.yaml/badge.svg)](https://github.com/jonesor/Rcompadre/actions/workflows/main_check.yaml) | [![R-CMD-check](https://github.com/jonesor/Rcompadre/actions/workflows/devel_build_check.yaml/badge.svg)](https://github.com/jonesor/Rcompadre/actions/workflows/devel_build_check.yaml) |
| [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) | [![codecov](https://codecov.io/gh/jonesor/Rcompadre/branch/main/graph/badge.svg?token=S9G2a5K9k9)](https://app.codecov.io/gh/jonesor/Rcompadre) | |
| ![Grand Total](http://cranlogs.r-pkg.org/badges/grand-total/Rcompadre) |[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/Rcompadre)](https://cran.r-project.org/package=Rcompadre)|
| ![CRAN](http://cranlogs.r-pkg.org/badges/Rcompadre)| | |
<!--- Continuous Integration Badges End --->
An R package to facilitate working with the [COM(P)ADRE](https://compadre-db.org/) Plant and Animal Matrix Population Databases.
## Installation
Install the stable release package from CRAN with:
```{r, eval=FALSE}
install.packages("Rcompadre")
```
Install the package from GitHub with:
```{r, eval=FALSE}
# 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
remotes::install_github("jonesor/Rcompadre", build_opts = NULL)
```
To install from the development branch use:
```{r, eval=FALSE}
remotes::install_github("jonesor/Rcompadre", ref = "devel")
```
## Usage
```{r, eval=FALSE}
library(Rcompadre)
```
#### Fetching a database
Fetch the most recent database version from [compadre-db.org](https://compadre-db.org/) with
```{r, eval=FALSE}
compadre <- cdb_fetch("compadre") # or use 'comadre' for the animal database
```
or load from a local `.RData` file with
```{r, eval=FALSE}
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
```{r, eval=FALSE}
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 `[`, `subset()` or `filter()`
```{r, eval=FALSE, results="hide"}
# subset to the first 10 rows
compadre[1:10, ]
# subset to the species 'Echinacea angustifolia'
subset(compadre, SpeciesAccepted == "Echinacea angustifolia")
# subset to the species 'Echinacea angustifolia'
filter(compadre, SpeciesAccepted == "Echinacea angustifolia")
```
#### 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.
```{r,eval=FALSE}
compadre_flags <- cdb_flag(compadre)
```
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.
```{r, eval=FALSE}
compadre_sub <- subset(
compadre_flags,
check_NA_A == FALSE & check_ergodic == TRUE
)
```
Finally, we'll use the `eigs()` function from the [popdemo](https://CRAN.R-project.org/package=popdemo) package to calculate the population growth rate for every matrix in `compadre_sub`.
```{r, eval=FALSE}
compadre_sub$lambda <- sapply(matA(compadre_sub), popdemo::eigs, what = "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.
For example to install version 0.1.0:
```{r, eval=FALSE}
remotes::install_github("jonesor/[email protected]")
```
See the Changelog for more details.
## Citation
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.
## Contributions
All contributions are welcome. Please note that this project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By participating in this project you agree to abide by its terms.
There are numerous ways of contributing.
1. You can submit bug reports, suggestions etc. by [opening an issue](https://github.com/jonesor/Rcompadre/issues).
2. 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](https://jarv.is/notes/how-to-pull-request-fork-github/).
3. You can get to know us and join as a collaborator on the main repository.
4. You are also welcome to email us.