Skip to contents

Requirements

  • R (>= 4.1)
  • just - runs the commands below (just list to see them all)
  • air - formats R code
  • gh - publishes releases to GitHub

Configuration

All in inst/config/:

  • tidy_data_sources.yml - current version and download url per dataset, read by get_*()
  • raw_<name>.yml - source urls per NHS Digital publication, read only when rebuilding data
  • shiny_app_datasets.yml - what shows up in the Shiny app’s dataset picker

Building the data

Each data-raw/<name>.R script downloads the source files from NHS Digital, cleans them, and writes a parquet file to data-raw/. Run one script directly, or just build-data to rebuild everything (this takes some time as it downloads the data).

Publishing a new version

  1. Add the new year’s source url to inst/config/raw_<name>.yml, then run data-raw/<name>.R (or just build-data) to rebuild the parquet in data-raw/
  2. Add a new entry at the top of the dataset’s list in tidy_data_sources.yml, with a placeholder url
  3. just release <dataset> <version> "<notes>" - uploads the parquet as a GitHub release
  4. Copy the real download url from the release page over the placeholder

Adding a new dataset

  1. Write data-raw/<name>.R and inst/config/raw_<name>.yml, following the existing pattern
  2. Add an entry to tidy_data_sources.yml. Set publication to the raw_<name>.yml base name and variant to usage or breakdowns. get_raw_source_periods() reads both.
  3. Export a get_<name>() function in R/get-data.R
  4. just release to publish it
  5. Add it to shiny_app_datasets.yml if it should appear in the app

Dataset names follow <source>_<coding system>. hesapc_icd10 means HES Admitted Patient Care, ICD-10. gp_snomed means GP, SNOMED CT. If a dataset has no single coding system, like QOF registers, use a short content word instead: qof_registers.

Checking codelists

check_codelists() uses the SNOMED CT History Substitution Table from NHS TRUD (Technology Reference data Update Distribution) item 276. data-raw/snomed_history.R builds it as the snomed_history dataset, and it is published as a GitHub release like the usage data. The TRUD item and release are set under snomed_history in inst/config/raw_trud.yml, which has one entry per dataset built from TRUD. Only rows with an active new code are kept, with the columns old_code, old_term, new_code, new_term and is_ambiguous, plus trud_release so the published file records the TRUD release it came from. Only pairs where the old or new code has GP usage are kept, because the check only reports codes with usage. Rebuild it after each new gp_snomed release, so new codes with usage are included.

Building it is the only step that needs an API key. Add TRUD_API_KEY=your-key to ~/.Renviron and restart R. Users of check_codelists() do not need a key.

The is_not_selected_with_usage column in R/check-codelists.R sets which linked codes not selected are reported. The report, @summary and the exit status all use it.

Coding systems come from the OpenCodelists API, with one request per organisation or user. Tagged versions are matched by tag and by hash. A codelist that moved to a new owner is not found, so it is skipped and listed in the report.

Codelist CSV files do not all have the same layout. rename_code_column() in R/opencodelists.R drops unnamed columns, such as a saved pandas index, and then uses the code column, or the first column if there is none.

The terminal command is in exec/opencodecounts.R and uses Rapp. Install it once with Rapp::install_pkg_cli_apps("opencodecounts"). The command runs the installed package, so run devtools::install() to try your changes in the terminal.

Running the app locally

run_app() downloads and caches data like any other user. Run cache_clear() first if you want to test against data you just published.

Deploying

just deploy copies the released parquet for every dataset into inst/app-data/ (this is gitignored), then deploys to Posit Connect Cloud. This means the hosted app reads data straight off disk and never calls GitHub at runtime, so a restart doesn’t need to download anything first. just deploy deploys the main app, just deploy beta deploys a separate beta app. The first time you deploy from a machine, you need to link your Posit Connect Cloud account by running rsconnect::connectCloudUser().