write_own_model.Rmd
You might want to write your own extension to the malaria models, in this vignette I will try and cover the easiest way of doing this.
You should start by cloning this github repository to your own
computer. If you are new to R package development the next best step is
to open the ICDMM.Rproj
file using RStudio.
If you write some new code in a file called
example_model.R
, you should save it in
inst/odin
with the other models. You then need to run
odin::odin_package()
, with the directory path of the
project inside the parenthesis, this will add a compiled version of your
odin model to the package files.
You will need to add your model name to the following bit of code in
line 44 of R/run_model.R
:
generator <- switch(model,
"odin_model" = odin_model,
"odin_model_emanators" = odin_model_emanators,
"odin_model_hrp2" = odin_model_hrp2,
"odin_model_IVM_SMChet" = odin_model_IVM_SMChet,
"example" = example,
stop(sprintf("Unknown model '%s'", model)))
This will allow for you to eventually run
run_model(model = "example")
to run your odin model.
The final step is to rebuild the R package, you can do this by pressing “Install and Restart” in the “Build” panel in RStudio (usually in the top right panels) or the usual keyboard is ctrl + shift + b (or cmd + shift + b on a mac)
The easiest way to develop your new package using github will be to
make a new branch. You can do this using the “New Branch” button in the
RStudio interface or by running
git checkout -b <branch name>
. You can then push this
new branch to github to do version control but your changes won’t affect
anything on the main branch. When you have finished working on your
model you can use github to create a pull request and we can merge it
with the main branch so that everyone downloading the package also
recieves your model as part of it.