Open goldingn opened 8 years ago
This is the preferred formula syntax, for:
(size | juvenile) ~ adult
(size | juvenile) ~ (size | juvenile)
adult ~ (size | larvae)
(size | adult) ~ (size | larvae)
will need to parse these cleanly, and use trait density (need a better name than that) transfuns for 1, 2, and 4. I.e. anything with a trait on the LHS (can just use the population vector for the RHS)
Code to parse these, with or without braces:
stripBraces <- function (x) {
if (as.character(x[[1]]) == '(') {
x <- x[[2]]
x <- stripBraces(x)
}
return (x)
}
getStage <- function (f, which = c('to', 'from')) {
which <- match.arg(which)
x <- switch(which,
to = f[[2]],
from = f[[3]])
if (length(x) == 1) {
stage <- as.character(x)
} else {
x <- stripBraces(x)
if (length(x) == 3 &
as.character(x[[1]]) == '|') {
stage <- as.character(x[[3]])
attr(stage, 'trait') <- as.character(x[[2]])
} else {
stop ('cannot parse transition formula')
}
}
return (stage)
}
This will enable age- or size-structured models, like IPMs.
This requires:
Initially this can just be a single trait, but possible to allow multiples (representing all combinations of bins for each trait as separate bins)