knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE )
The purpose of this vignette is to document how this package has been developed. The package utilises testthat
, Travis CI{target="_blank"} and Docker{target="_blank"} to allow unit testing and continuous integration.
The aim of this package is to generate routine reports for MSF OCA HIS EMR platform. The database provides the capacity for projects to record health data for patients who are repeatdely seen in the same clinic. At the time of development, this included people suffering from TB, HIV and HCV.
The package will access the PostgreSQL server to pull, clean then present relevent data for each report that has been developed. This requires authentication with the PostgreSQL server, sending appropriate SQL queries followed by cleaning and presentation using R, the knitr
and rmarkdown
packages.
The package uses routine testthat
architecture such that unit tests are stored in the tests/testthat/
folder and test data is saved in inst/testdata/
. Raw data scripts for reproducibility are saved in the data-raw/
folder.
An additional feature for unit testing is the use of a PostgreSQL docker container. Start up and kill bash scripts are stored in exec/
folder. Spinning up a PostgreSQL docker container allows testing of the access_postgres()
function using environment variables for connection configuration. Test data has been generated for each report template to allow full testing of the procerss. This is again stored in the data-raw
folder.
In addition, build testing is configured to use Travis CI{target="_blank"} which is monitors the GitHub repository for any commit from any branch. This triggers a build process with some custom configuration. This configuration is stored in the .travis.yml
file. Before installation, the PostgreSQL docker container is started to allow testing of the access_postgres()
function through testthat
unit testing.
The package only exports one function - render_report()
. It will require one argument - report_name
which allows the user to choose which report to generate. In addition, arguments to configure the PostgreSQL database connection are included, but default to environment variables.
# Generating reports hisreportr::render_report(report_name = "hcv_month", quiet = TRUE)
These environment variables are self-explanatory and as follows:
These should be saved in the .Renviron
file so that these environment variables can be defined at start up. A long tutorial can be found here{target="_blank"}, or a more succinct option is here{target="_blank"}. The simplest approach is to save a .Renviron
file in the user's home directory and include the following syntax:
# Syntax for .Renviron file PGRES_HOST=pgres_srv.hostname.org
Within the package, SQL queries and additional data required for data cleaning is stored as an internal data set. For editing, the script is saved as data-raw/internal_data.R
while that data itself is saved as R/sysdata.rda
. This data is automatically loaded into the environment when the package is called with library()
.
Various functions within the package use this internal data to appropriately query the PostgreSQL database and perform any cleaning that's required prior to reporing through R-markdown files found at inst/rmarkdown/
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.