a b/R/get_cpp_api.R
1
2
#' Access internal C++ rountines used in outbreaker2
3
#'
4
#' This function returns an environment containing all C++ functions (bound to R
5
#' using Rcpp) used for priors, likelihoods, and movements of parameters in
6
#' outbreaker2.
7
#'
8
#' @export
9
#'
10
#' @author Thibaut Jombart (\email{thibautjombart@@gmail.com}).
11
#'
12
#' @return
13
#'
14
#' An environment containing Rcpp bindings to C++ functions used internally in
15
#' outbreaker2. All functions are named as cpp_[type]_[component], where 'type'
16
#' can be:
17
#'
18
#' \itemize{
19
#'
20
#' \item 'prior': prior computation.
21
#'
22
#' \item 'll':  likelihood computation.
23
#'
24
#' \item 'move': movement of parameters or augmented data.
25
#'
26
#' }
27
#'
28
#' And where 'component' can be:
29
#'
30
#' \itemize{
31
#'
32
#' \item 'mu': (parameter) mutation rate.
33
#'
34
#' \item 'pi': (parameter) reporting probability.
35
#'
36
#' \item 'lambda': (parameter) non-infectious contact rate.
37
#'
38
#' \item 'eps': (parameter) contact reporting coverage.
39
#' 
40
#' \item 'alpha': (augmented data) ancestries of the cases.
41
#'
42
#' \item 'kappa': (augmented data) generation between cases on transmission
43
#' chains.
44
#'
45
#' \item 't_inf': (augmented data) dates of infections.
46
#'
47
#' \item 'timing_infections': (likelihood component) timing between infectors and
48
#' infectees.
49
#'
50
#' \item 'timing_sampling': (likelihood component) timing between infection and
51
#' reporting / isolation.
52
#'
53
#' \item 'timing': (likelihood component) sum of the two timing components.
54
#' 
55
#' \item 'genetic': (likelihood component) genetic diversity accumulated along
56
#' transmission chains.
57
#' 
58
#' \item 'reporting': (likelihood component) reporting of cases.
59
#' 
60
#' \item 'all': (likelihood component) sum of all likelihood components.
61
#'
62
#' \item 'swap_cases': (type of movement) swap infectors and infectees on a
63
#' transmission tree.
64
#'
65
#' }
66
#'
67
#' For a description of the arguments of these functions, see the Rcpp_API
68
#' vignette (\code{vignette("Rcpp_API", package = "outbreaker2")}).
69
#'
70
#' 
71
#' @examples
72
#'
73
#' ## get functions in an environment
74
#' api <- get_cpp_api()
75
#' api
76
#'
77
#' ## check content of the environment
78
#' ls(api)
79
#'
80
#' ## test the prior for mu
81
#' args(api$cpp_prior_mu)
82
#'
83
#' config <- create_config()
84
#'
85
#' api$cpp_prior_mu(list(mu = 0.00123), config)
86
#' 
87
#' dexp(0.00123, rate = config$prior_mu, log = TRUE)
88
#' 
89
get_cpp_api <- function() {
90
    pkg_env <- asNamespace("outbreaker2")
91
    regxp <- "^cpp_(ll|prior|move)"
92
    names_cpp_functions <- sort(ls(envir = pkg_env, pattern = regxp))
93
94
    out_env <- new.env()
95
    
96
    for (e in names_cpp_functions) {
97
        f <- get(e, envir = pkg_env)
98
        assign(e, f, envir = out_env)
99
    }
100
101
    return(out_env)
102
}