Creates a CompadreDB object from data provided by the user in the form of matrices and metadata. Users can provide either a list of A matrices (i.e. the whole matrix population model) or lists of process-based submatrices matU, matFand matC. In this latter case, we assume that matA = matU + matF + matC. If only one type of the submatrices are provided, the others are assumed to be 0. If only the A matrices are provided, the submatrices are recorded as `NA`.

cdb_build_cdb(
  mat_a = NULL,
  mat_u = NULL,
  mat_f = NULL,
  mat_c = NULL,
  stages = NULL,
  version = NULL,
  metadata = NULL
)

Arguments

mat_a

A `list` of A matrices

mat_u

A `list` of U matrices (representing survival and growth)

mat_f

A `list` of F matrices (representing sexual reproduction)

mat_c

A `list` of C matrices (representing clonal reproduction)

stages

A `list` of stage definitions provided as `data.frame`s that include two columns: `MatrixClassOrganized` and `MatrixClassAuthor`. If this argument is not provided, numeric stage names are generated automatically

version

An optional string allowing users to add version information to their output object. If this argument is not provided the current date and time is used.

metadata

A `data.frame` of metadata associated with each matrix. Metadata should be provided by row in the same order as the matrices are placed in the lists.

Value

A valid CompadreDB object

See also

Other data acquisition: cdb_fetch(), cdb_metadata()

Author

Owen R. Jones <jones@biology.sdu.dk>

Examples

# If you only have A matrices

mat_a1 <- rbind(
  c(0.1, 1.9),
  c(0.5, 0.7)
)

mat_a2 <- rbind(
  c(0.2, 1.4, 2.3),
  c(0.6, 0.3, 1.1),
  c(0.2, 0.2, 1.5)
)

mat_a3 <- rbind(
  c(0.1, 2.1),
  c(0.3, 0.4)
)

# Place the matrices into a list
mat_a_list <- mget(ls(pattern = "mat_a[0-9]"))

my_compadre <- cdb_build_cdb(mat_a = mat_a_list, version = "testrun")
#> Warning: Metadata does not include a `SpeciesAccepted` column, so number
#>               of species not provided when viewing object.
my_compadre
#> A COM(P)ADRE database ('CompadreDB') object with ?? SPECIES and 3 MATRICES.
#> 
#> # A tibble: 3 × 2
#>   mat        matrixID
#>   <list>        <int>
#> 1 <CompdrMt>        1
#> 2 <CompdrMt>        2
#> 3 <CompdrMt>        3


mat_u1 <- rbind(
  c(0.1, 0.0),
  c(0.5, 0.7)
)

mat_u2 <- rbind(
  c(0.2, 0.0, 0.0),
  c(0.6, 0.3, 1.1),
  c(0.2, 0.2, 1.5)
)

mat_f1 <- rbind(
  c(0.0, 1.9),
  c(0.0, 0.0)
)

mat_f2 <- rbind(
  c(0.0, 1.4, 2.3),
  c(0.0, 0.0, 0.0),
  c(0.0, 0.0, 0.0)
)

mat_u_list <- mget(ls(pattern = "mat_u[0-9]"))
mat_f_list <- mget(ls(pattern = "mat_f[0-9]"))

meta <- data.frame(idNum = 1:2, SpeciesAccepted = c("A", "B"), x = 4:5)

stageInfo <- list(
  data.frame(
    MatrixClassOrganized = rep("active", 2),
    MatrixClassAuthor = c("small", "large")
  ),
  data.frame(
    MatrixClassOrganized = rep("active", 3),
    MatrixClassAuthor = c("small", "medium", "large")
  )
)


my_compadre <- cdb_build_cdb(
  mat_u = mat_u_list, mat_f = mat_f_list,
  metadata = meta, stages = stageInfo
)
my_compadre
#> A COM(P)ADRE database ('CompadreDB') object with 2 SPECIES and 2 MATRICES.
#> 
#> # A tibble: 2 × 4
#>   mat        idNum SpeciesAccepted     x
#>   <list>     <int> <chr>           <int>
#> 1 <CompdrMt>     1 A                   4
#> 2 <CompdrMt>     2 B                   5

my_compadre <- cdb_build_cdb(
  mat_u = mat_u_list, mat_f = mat_f_list,
  metadata = meta
)
my_compadre
#> A COM(P)ADRE database ('CompadreDB') object with 2 SPECIES and 2 MATRICES.
#> 
#> # A tibble: 2 × 4
#>   mat        idNum SpeciesAccepted     x
#>   <list>     <int> <chr>           <int>
#> 1 <CompdrMt>     1 A                   4
#> 2 <CompdrMt>     2 B                   5