-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
265 lines (222 loc) · 6.12 KB
/
README.Rmd
File metadata and controls
265 lines (222 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# nhstt
<!-- badges: start -->
[](https://github.com/bennettoxford/nhstt/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/bennettoxford/nhstt)
<!-- badges: end -->
> **This package is under active development. Breaking changes are likely.**
`nhstt` provides access to publicly available NHS Talking Therapies reports in a tidy data format.
## Installation
Install the development version from GitHub:
``` r
# install.packages("pak")
pak::pak("bennettoxford/nhstt")
```
## Usage
```{r example, eval = FALSE}
library(nhstt)
# Load annual key measures dataset for financial year 2024-25
km_annual <- get_key_measures_annual(periods = "2024-25")
# Load all monthly activity performance datasets
# Note, this will take a few minutes
ap_monthly <- get_activity_performance_monthly()
```
## Available NHS Talking Therapies data
### Annual data
```{r datasets-annual, echo = FALSE, message = FALSE}
df_nhstt_reports <- nhstt:::available_nhstt_reports() |>
dplyr::filter(!stringr::str_detect(title, "metadata")) |>
dplyr::filter(frequency == "annual") |>
dplyr::select(
get_function,
first_period,
last_period,
n_periods,
version
) |>
dplyr::mutate(get_function = paste0("`", get_function, "()`"))
knitr::kable(
df_nhstt_reports,
row.names = FALSE,
col.names = c(
"Function",
"First period",
"Last period",
"Count periods",
"Version"
),
align = c("l", "l", "l", "r", "r")
)
```
### Monthly data
```{r datasets-monthly, echo = FALSE, message = FALSE}
df_nhstt_reports <- nhstt:::available_nhstt_reports() |>
dplyr::filter(!stringr::str_detect(title, "metadata")) |>
dplyr::filter(frequency == "monthly") |>
dplyr::select(
get_function,
first_period,
last_period,
n_periods,
version
) |>
dplyr::mutate(get_function = paste0("`", get_function, "()`"))
knitr::kable(
df_nhstt_reports,
row.names = FALSE,
col.names = c(
"Function",
"First period",
"Last period",
"Count periods",
"Version"
),
align = c("l", "l", "l", "r", "r")
)
```
### Metadata
```{r datasets-metadata, echo = FALSE, message = FALSE}
df_nhstt_reports <- nhstt:::available_nhstt_reports() |>
dplyr::filter(stringr::str_detect(title, "metadata")) |>
dplyr::select(
get_function,
first_period,
last_period,
n_periods,
version
) |>
dplyr::mutate(get_function = paste0("`", get_function, "()`")) |>
dplyr::distinct()
knitr::kable(
df_nhstt_reports,
row.names = FALSE,
col.names = c(
"Function",
"First period",
"Last period",
"Count periods",
"Version"
),
align = c("l", "l", "l", "r", "r")
)
```
## Time to download and tidy the data
```{r run-benchmarks, echo = FALSE, message = FALSE, warning = FALSE}
library(nhstt)
format_time <- function(elapsed) {
if (elapsed < 1) {
paste0(round(elapsed, 2), " sec")
} else if (elapsed < 60) {
paste0(round(elapsed, 1), " sec")
} else {
paste0(round(elapsed / 60, 1), " min")
}
}
benchmark_dataset <- function(dataset, period, frequency, get_function) {
n_periods <- length(nhstt:::list_available_periods(dataset, frequency))
raw_path <- nhstt:::get_raw_cache_path(dataset, period, frequency)
tidy_path <- nhstt:::get_tidy_cache_path(dataset, period, frequency)
if (file.exists(raw_path)) {
unlink(raw_path)
}
if (file.exists(tidy_path)) {
unlink(tidy_path)
}
download_time <- system.time({
nhstt:::read_raw(dataset, period, frequency, use_cache = FALSE)
})["elapsed"]
tidy_time <- system.time({
get_function(periods = period, use_cache = TRUE)
})["elapsed"]
total_time <- (download_time + tidy_time) * n_periods
list(
download = format_time(download_time),
tidy = format_time(tidy_time),
total = format_time(total_time)
)
}
time_km_annual <- benchmark_dataset(
"key_measures_annual",
"2024-25",
"annual",
get_key_measures_annual
)
time_proms_annual <- benchmark_dataset(
"proms_annual",
"2024-25",
"annual",
get_proms_annual
)
time_therapy_position_annual <- benchmark_dataset(
"therapy_position_annual",
"2024-25",
"annual",
get_therapy_position_annual
)
time_ap_monthly <- benchmark_dataset(
"activity_performance_monthly",
"2025-08",
"monthly",
get_activity_performance_monthly
)
```
Approximate download and processing times per period.
Your times might be a bit faster or slower depending on your internet speed and computer setup.
```{r performance-table, echo = FALSE}
performance_data <- tibble::tibble(
Function = c(
"`get_key_measures_annual()`",
"`get_proms_annual()`",
"`get_therapy_position_annual()`",
"`get_activity_performance_monthly()`"
),
download_per_period = c(
time_km_annual$download,
time_proms_annual$download,
time_therapy_position_annual$download,
time_ap_monthly$download
),
tidy_per_period = c(
time_km_annual$tidy,
time_proms_annual$tidy,
time_therapy_position_annual$tidy,
time_ap_monthly$tidy
),
total_all_periods = c(
time_km_annual$total,
time_proms_annual$total,
time_therapy_position_annual$total,
time_ap_monthly$total
)
)
knitr::kable(
performance_data,
row.names = FALSE,
col.names = c(
"Function",
"Download per period",
"Tidy per period",
"Total (all periods)"
),
align = c("l", "r", "r", "r")
)
```
## For developers
See [DEVELOPERS.md](DEVELOPERS.md).
## Licence
### R package
The `nhstt` package is licensed under the [MIT License](LICENSE.md).
### NHS Talking Therapies data
All NHS Talking Therapies data is Copyright NHS England and licensed under the [Open Government Licence v3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).
Contains public sector information licensed under the Open Government Licence v3.0.