How the-strategy-unit/nhp_reskit works
Purpose and package surface
reskit is an R package for turning NHP model-result datasets into analysis-ready summaries, presentation tables, and plots. The public entry surface is the exported R functions documented in man/; package initialization and namespace identity are defined by R/reskit-package.R, DESCRIPTION, and NAMESPACE.
Results ingestion boundary
The principal input boundary is Azure Blob Storage accessed through azkit, with Azure authentication and AZ_STORAGE_EP supplied externally. read_results_parquet_files() loads a results folder into a named list of tibbles, optionally selecting table basenames. Core implementation: R/read_results_parquet_files.R; Azure/GitHub-oriented retrieval helpers: R/get_github_file.R, R/helpers.R.
Result normalization and compatibility
Raw model-result lists are adapted before reporting. shim_results() provides a compatibility/normalization layer for result structures, while shared transformations, result emptiness handling, and baseline/horizon calculations support downstream compilers. Paths: R/shim_results.R, R/helpers.R, R/calculate_principal_stats.R.
Principal activity and LOS reporting pipeline
Dedicated compilation stages derive principal point-of-delivery (POD), detailed activity, and length-of-stay datasets from model results. These datasets then feed table builders and export functions rather than exposing raw source tables directly. Paths: R/principal_pod_data.R, R/detailed_activity_data.R, R/principal_los_data.R.
Distribution analysis pipeline
Distribution-specific preparation compiles both plot-level observations and summary-level metrics, then renders cumulative or beeswarm visualizations and formatted summary tables. This separates statistical shaping from presentation. Paths: R/distribution_plot_data.R, R/distribution_summary_data.R, R/distribution_plots.R.
Impact analysis pipeline
Impact reporting produces grouped and TPMA-oriented impact datasets and corresponding plots. It appears to combine model outcomes with geographic/label lookups, maintaining a distinct path from POD and distribution reporting. Paths: R/impact_data.R, R/impact_plots.R, R/get_principal_pods.R.
Presentation and exports
The package’s output boundary is primarily gt HTML tables and plot objects, with explicit export routines for compiled datasets. Shared table formatting and no-data presentation are centralized rather than repeated per report family. Paths: R/tables.R, R/demo_results_tables.R, R/impact_plots.R.
Runtime, delivery, and documentation
This is an R-package runtime intended for use inside analysts’ R sessions, not a standalone service. Azure Storage and azkit are material external dependencies; GitHub may supply supporting lookup/assets through retrieval helpers. Package checks and documentation publishing run through GitHub Actions: .github/workflows/R-CMD-check.yaml, .github/workflows/pkgdown.yaml; the usage-oriented guide is vignettes/plots_tables.qmd.
Main entry points: calculate_principal_stats.R Shared result transforms · impact_data.R Impact data compiler · tables.R Tables & dataset exports · distribution_plot_data.R Distribution data compilers
Components 18
Ingestion
- Azure Blob Storage · Results source; credentials and endpoint are external.
- Azure/GitHub retrieval · Retrieves result files and supporting assets.
R/get_github_file.R - Parquet results reader · Loads selected result tables into named tibble lists.
R/read_results_parquet_files.R - Model result tables
Result Compilation
- Results compatibility shim · Adapts result structures for reporting.
R/shim_results.R - Shared result transforms · Handles empty results plus baseline and horizon calculations.
R/calculate_principal_stats.R
Reporting Pipelines
- POD, activity & LOS compilers · Derives reporting datasets from normalized results.
R/principal_pod_data.R - Distribution data compilers · Creates plot observations and summary metrics.
R/distribution_plot_data.R - Impact data compiler · Builds grouped and TPMA impact datasets.
R/impact_data.R - Principal POD lookup · Supplies geographic and label context for impact reporting.
R/get_principal_pods.R - Distribution plots & tables · Renders cumulative/beeswarm plots and formatted summaries.
R/distribution_plots.R - Impact plots
R/impact_plots.R
Delivery
- Tables & dataset exports · Centralizes gt formatting, no-data views, and exports.
R/tables.R - Tables, plots & exports · gt HTML tables, plot objects, and compiled datasets.
- Checks & documentation publishing · Runs package checks and publishes documentation.
.github/workflows/R-CMD-check.yaml - Plots and tables guide
vignettes/plots_tables.qmd
Other components
- Analyst R session · Interactive package consumer.
- reskit public API · Exported functions and package initialization.
R/reskit-package.R
Connections 20
- Analyst R session → reskit public API: uses
- reskit public API → Parquet results reader: ingests results
- Azure Blob Storage → Azure/GitHub retrieval: results files
- Azure/GitHub retrieval → Parquet results reader: retrieved files
- Parquet results reader → Model result tables: loads
- Model result tables → Results compatibility shim: normalizes
- Results compatibility shim → Shared result transforms: standardized results
- Shared result transforms → POD, activity & LOS compilers: report-ready inputs
- Shared result transforms → Distribution data compilers: report-ready inputs
- Shared result transforms → Impact data compiler: report-ready inputs
- Principal POD lookup → Impact data compiler: labels and geography
- Distribution data compilers → Distribution plots & tables: plot and summary data
- Impact data compiler → Impact plots: impact datasets
- POD, activity & LOS compilers → Tables & dataset exports: compiled datasets
- Distribution data compilers → Tables & dataset exports: summary datasets
- Impact data compiler → Tables & dataset exports: impact datasets
- Distribution plots & tables → Tables, plots & exports: plots and tables
- Impact plots → Tables, plots & exports: plots
- Tables & dataset exports → Tables, plots & exports: gt tables and exports
- Checks & documentation publishing → Plots and tables guide: publishes