-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0104-step-growth.R
42 lines (36 loc) · 1.16 KB
/
0104-step-growth.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
#' ---
#' title: "Simple growth difference equation model"
#' author: "Richard Reeve"
#' date: '`r format(Sys.Date(), "%B %d %Y")`'
#' output: html_document
#' ---
step_deterministic_growth <- function(latest, growth.rate) {
#' A simple deterministic exponential growth model
#'
#' Run one step of a simple deterministic exponential growth model
#'
#' Arguments:
#'
#' - latest -- a data frame containing the latest population count
#' (column is 'count')
#'
#' - growth.rate -- the growth rate
#'
#' Returns:
#'
#' - a data.frame containing the updated population
## Calculate population changes
new.additions <- growth.rate * latest$count
next.count <- latest$count + new.additions
## 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_growth,
merge = FALSE)$variables) != 0) {
stop(
"Function step_deterministic_growth() may not use global variable(s): ",
findGlobals(step_deterministic_growth, merge = FALSE)$variables
)
}