Skip to content

Commit

Permalink
SIR wrapper workin #2
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Aug 19, 2022
1 parent b0cbcb1 commit 1ca49a5
Show file tree
Hide file tree
Showing 8 changed files with 12,768 additions and 44 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build: update
Rscript -e 'Rcpp::compileAttributes()' && \
Rscript -e 'roxygen2::roxygenize()' && \
R CMD INSTALL .
update:
rsync -avz ../../research/world-epi/epiworld.hpp inst/include/epiworld.hpp

.PHONY: build update
20 changes: 20 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Generated by cpp11: do not edit by hand

ModelSIR <- function(name, prevalence, infectiousness, recovery) {
.Call(`_epiworldR_ModelSIR`, name, prevalence, infectiousness, recovery)
}

init <- function(m, days, seed) {
.Call(`_epiworldR_init`, m, days, seed)
}

print <- function(m) {
.Call(`_epiworldR_print`, m)
}

agents_smallworld <- function(m, n, k, d, p) {
.Call(`_epiworldR_agents_smallworld`, m, n, k, d, p)
}

run <- function(m) {
.Call(`_epiworldR_run`, m)
}

sum_cpp <- function(x) {
.Call(`_epiworldR_sum_cpp`, x)
}
39 changes: 23 additions & 16 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ This is a basic example which shows you how to solve a common problem:

```{r example}
library(epiworldR)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
```{r cars}
summary(cars)
# Creating a SIR model
sir <- epiworldR:::ModelSIR(
name = "COVID-19",
prevalence = .1,
infectiousness = .9,
recovery = .3
)
# Adding a Small world population
epiworldR:::agents_smallworld(
sir,
n = 10000,
k = 5,
d = FALSE,
p = .01
)
# Initializing
epiworldR:::init(sir, days = 100, seed = 1912)
# Running and printing
epiworldR:::run(sir)
epiworldR:::print(sir)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
87 changes: 60 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,65 @@ This is a basic example which shows you how to solve a common problem:

``` r
library(epiworldR)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`?
You can include R chunks like so:

``` r
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
# Creating a SIR model
sir <- epiworldR:::ModelSIR(
name = "COVID-19",
prevalence = .1,
infectiousness = .9,
recovery = .3
)

# Adding a Small world population
epiworldR:::agents_smallworld(
sir,
n = 10000,
k = 5,
d = FALSE,
p = .01
)
#> [1] 0

# Initializing
epiworldR:::init(sir, days = 100, seed = 1912)
#> [1] 0

# Running and printing
epiworldR:::run(sir)
#> Running the model...
#> _________________________________________________________________________
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> [1] 0
epiworldR:::print(sir)
#>
#> ________________________________________________________________________________
#> SIMULATION STUDY
#>
#> Population size : 10000
#> Number of entitites : 0
#> Days (duration) : 100 (of 100)
#> Number of variants : 1
#> Last run elapsed t : 97.00ms
#> Rewiring : off
#>
#> Virus(es):
#> - COVID-19 (baseline prevalence: 10.00%)
#>
#> Tool(s):
#> (none)
#>
#> Model parameters:
#> - Infectiousness : 0.9000
#> - Prob. of Recovery : 0.3000
#>
#> Distribution of the population at time 100:
#> - (0) Susceptible : 9000 -> 0
#> - (1) Infected : 1000 -> 0
#> - (2) Recovered : 0 -> 10000
#>
#> Transition Probabilities:
#> - Susceptible 0.29 0.71 0.00
#> - Infected 0.00 0.73 0.27
#> - Recovered 0.00 0.00 1.00
#> [1] 0
```

You’ll still need to render `README.Rmd` regularly, to keep `README.md`
up-to-date. `devtools::build_readme()` is handy for this. You could also
use GitHub Actions to re-render `README.Rmd` every time you push. An
example workflow can be found here:
<https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

<img src="man/figures/README-pressure-1.png" width="100%" />

In that case, don’t forget to commit and push the resulting figure
files, so they display on GitHub and CRAN.
Loading

0 comments on commit 1ca49a5

Please sign in to comment.