Skip to content

Development

Stef Piatek edited this page Jan 15, 2025 · 6 revisions

Developer set up instructions

Make sure you have a recent version of R (>= 4.0.0) installed. Though not required, RStudio is recommended as an IDE, as it has good support for R package development and Shiny.

  1. Clone this repository

  2. You will also need some packages installed on your OS for the next stage to work. If you don't perform this step the next stage will tell you (gradually) which packages to install, but it will be quicker if you install them ahead of time. The packages you need are as follows:

    • For Ubuntu/Debian: libcurl4-openssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libxml2-dev
  3. Open navigate to preprocessing directory and open the omopcat.preprocesssing.Rproj file in Rstudio

  4. Install {renv} and restore the project library by running the following from an R console in the project directory:

    install.packages("renv")
    renv::restore()
  5. Configure the "low-frequency statistics masking" feature, by defining a threshold and a replacement value (values below the threshold will be replaced, in the summary statistics), as environment variables.

    When running the app locally in development mode, these variables need to be defined in a .Renviron file. To add and edit this file locally, run

    usethis::edit_r_environ("project")

    and paste the following lines in

    LOW_FREQUENCY_THRESHOLD=5
    LOW_FREQUENCY_REPLACEMENT=2.5
    
  6. To preview the app locally, run the following from an R console within the project directory:

    golem::run_dev()

The dev/02_dev.R script contains a few helper functions to get you started.

Install pre-commit

We use the pre-commit framework to run automated checks before committing code. To set this up locally, follow the steps below.

  1. Make sure you have pre-commit installed on your machine, installation instructions here
  2. Install the precommit R package from within R with
    install.packages("precommit")
  3. Initialise precommit in your local repo, from within R
    precommit::use_precommit(config_source = "./.pre-commit-config.yaml")

For more information on the available hooks for R, see the precommit documentation.

Updating the renv lockfile

Make sure to regularly run renv::status(dev = TRUE) to check if your local library and the lockfile are up to date.

When adding a new dependency, install it in the renv library with

renv::install("package_name")

and then use it in your code as usual. renv will pick up the new package if it's installed and used in the project.

To update the lockfile, run

renv::snapshot(dev = TRUE)

The dev = TRUE argument ensures that development dependencies (e.g. those recorded under Suggests in the DESCRIPTION file) are also included in the lockfile.

Coding style

We'll mainly follow the tidyverse style guide. The {styler} package can be used to automatically format R code to this style, by regularly running

styler::style_pkg()

within the project directory. It's also recommended to install {lintr} and regularly run

lintr::lint_package()

(or have it run automatically in your IDE).

Clone this wiki locally