[dfe06d]: / R / get_cpp_api.R

Download this file

103 lines (98 with data), 2.6 kB

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