Diff of /vignettes/Rcpp_API.Rmd [000000] .. [dfe06d]

Switch to unified view

a b/vignettes/Rcpp_API.Rmd
1
---
2
title: "outbreaker2: Rcpp API"
3
author: "Thibaut Jombart"
4
date: "`r Sys.Date()`"
5
output:
6
   rmarkdown::html_vignette:
7
     toc: true
8
     toc_depth: 2
9
vignette: >
10
  %\VignetteIndexEntry{outbreaker2: Rcpp API}
11
  %\VignetteEngine{knitr::rmarkdown}
12
  %\VignetteEncoding{UTF-8}
13
---
14
15
16
17
# List of available functions
18
19
The C++ functions bound to R via Rcpp used in *outbreaker2* for priors,
20
likelihoods and movements are not visible to the user, as they are not exported
21
by the package. However, advanced users can access these functions using `get_cpp_api()`, which returns an environment with all relevant functions:
22
23
```{r}
24
library(outbreaker2) 
25
26
## get all functions in an environment
27
x <- get_cpp_api()
28
x
29
30
## check content
31
ls(x)
32
33
## all functions are Rcpp bindings to a C++ function
34
x$cpp_ll_all
35
36
```
37
38
39
40
# Function signatures
41
42
These functions take the following arguments:
43
```{r, arguments}
44
45
list_args <- lapply(x, args)[ls(x)]
46
list_args
47
48
```
49
50
Arguments are detailed in the next section.
51
52
53
54
# Arguments
55
56
Arguments of the Rcpp-bound C++ functions are:
57
```{r}
58
59
list_formals <- lapply(x, formals)
60
args <- sort(unique(unlist(lapply(list_formals, names))))
61
args
62
63
```
64
65
- **`alpha`**: a vector of integers of length 'N' (number of cases), indicating
66
    infectors of each case, with values from 1 to N; missing values should be
67
    `NA`
68
69
- **`config`**: a list containing configuration settings as returned by
70
    `create_config`
71
72
- **`custom_function`**: a R function for a custom prior, with a single
73
    argument, which must be a list of parameters and augmented data with the
74
    class `outbreaker_param`; returned values must be **on the log scale**
75
76
- **`custom_functions`**: a list of R functions obeying the rules of
77
`custom_function`, named according to the priors; currently available names are:
78
79
```{r, echo = FALSE} 
80
81
temp <- sub("cpp_prior_", "", ls(x, pattern = "cpp_prior.*"))
82
setdiff(temp, "all") 
83
84
```
85
86
- **`custom_ll`**: a R function for a custom likelihood, taking two arguments:
87
    `data` (see `data`), and `param` (see `param`)
88
89
- **`custom_prior`**: same as `custom_function`
90
91
- **`data`**: a valid 'outbreaker_data' list
92
93
- **`i`**: an integer scalar indicating the index of a case, from 1 to N (number of cases) 
94
95
- **`list_custom_ll`**: a list of R functions obeying the rules of `custom_ll`,
96
    named according to the computed likelihood component; available names are:
97
98
```{r, echo = FALSE}
99
temp <- sub("cpp_ll_", "", ls(x, pattern = "cpp_ll.*"))
100
setdiff(temp, c("timing", "all"))       
101
```
102
103
- **`param`**: a list containing parameters and augmented data with the class
104
    `outbreaker_param`
105
106
- **`t_inf`**: a vector of integers of length N (number of cases), indicating
107
    infection dates of each case; missing values should be `NA`
108
109
110
- **`x`**: a vector of integers to be sampled from