-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0105-step-birth-death.R
45 lines (39 loc) · 1.29 KB
/
0105-step-birth-death.R
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
#' ---
#' title: "Simple birth-death difference equation model"
#' author: "Richard Reeve"
#' date: '`r format(Sys.Date(), "%B %d %Y")`'
#' output: html_document
#' ---
step_deterministic_birth_death <- function(latest, birth.rate, death.rate) {
#' A simple deterministic exponential birth-death model
#'
#' Run one step of a simple deterministic exponential birth-death model
#'
#' Arguments:
#'
#' - latest -- a data frame containing the latest population count
#' (column is 'count')
#'
#' - birth.rate -- the birth rate
#'
#' - death.rate -- the death rate
#'
#' Returns:
#'
#' - a data.frame containing the updated population
## Calculate population changes
new.births <- birth.rate * latest$count
new.deaths <- death.rate * latest$count
next.count <- latest$count + new.births - new.deaths
## Return data frame containing next population count
data.frame(count = next.count)
}
#' #### Does the function works without any external (global) information?
library(codetools)
if (length(findGlobals(step_deterministic_birth_death,
merge = FALSE)$variables) != 0) {
stop(
"Function step_deterministic_birth_death() may not use global variable(s): ",
findGlobals(step_deterministic_birth_death, merge = FALSE)$variables
)
}