Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft completed - road-safety #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@
#'
"places_personal_crime"

#' Road safety (2023)
#'
#' A dataset containing number of people killed or seriously injured in each
#' Northern Irish Council Area in 2023 (latest available data).
#'
#' @format A data frame with 11 rows and 3 variables:
#' \describe{
#' \item{ltla24_code}{Local Authority Code}
#' \item{road_accident_count}{Number of people killed or seriously injured, per Local Authority}
#' \item{year}{Year}
#'
#' ...
#' }
#' @source \url{https://www.psni.police.uk/about-us/our-publications-and-reports/official-statistics/road-traffic-collision-statistics}
"places_road_safety"

#' Rate of Self-Harm Related Admissions per 100,000 (2018/19-2022/23)
#'
#' A dataset containing statistics on the rate of self-harm related admissions
Expand Down
51 changes: 51 additions & 0 deletions data-raw/healthy-places/road-safety.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ---- Load packages ----
library(tidyverse)
library(geographr)
library(readxl)

# ---- Get data and clean ----
# LA Codes
ltla_lookup <- lookup_ltla_ltla |>
filter(str_detect(ltla23_code, "N")) |>
select(ltla23_code, ltla23_name)

# Road Safety Data
# Source: https://www.psni.police.uk/about-us/our-publications-and-reports/official-statistics/road-traffic-collision-statistics

url <- "https://www.psni.police.uk/sites/default/files/2024-03/2023%20Key%20Statistics%20tables.xlsx"
temp_file <- tempfile(fileext = ".xlsx")
download.file(url, temp_file, mode = "wb")

road_safety_raw <- read_excel(temp_file, sheet = 6, skip = 5)

road_safety <- road_safety_raw |>
select(
ltla23_name = `Area`,
accident_count = `Total...11`
) |>
slice(1:11) |>
mutate(
ltla23_name = ltla23_name |>
str_replace_all("&", "and") |>
str_replace_all("Belfast City", "Belfast") |>
str_replace_all("Lisburn & Castlereagh City", "Lisburn and Castlereagh")
)

# Join datasets
places_road_safety <- ltla_lookup |>
left_join(road_safety, by = "ltla23_name") |>
mutate(
accident_count = case_when(
is.na(accident_count) & ltla23_code == "N09000007" ~ 615,
TRUE ~ accident_count
),
year = "2023"
) |>
select(
ltla24_code = ltla23_code,
road_accident_count = accident_count,
year
)

# ---- Save output to data/ folder ----
usethis::use_data(places_road_safety, overwrite = TRUE)
Binary file added data/places_road_safety.rda
Binary file not shown.
27 changes: 27 additions & 0 deletions man/places_road_safety.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
| Healthy Places | Low-Level Crime | :x: | :x: | :x: | :x: Data unavailable. | :x: |
| Healthy Places | Air Pollution | 2019 | [DEFRA](https://uk-air.defra.gov.uk/data/pcm-data) | [OGL3](https://www.gov.scot/crown-copyright/) | :heavy_check_mark: | :heavy_check_mark: |
| Healthy Places | Noise Complaints | 2024 | [DAERA](https://www.daera-ni.gov.uk/sites/default/files/publications/daera/Noise%20Complaint%20Statistics%20for%20NI%202023-24.PDF) | [OGL3](https://www.ninis2.nisra.gov.uk/public/terms.aspx) | :heavy_exclamation_mark: Raw data currently unavailable (only in a report). Need to contact aeqteam@daera-ni.gov.uk and ask for raw data in Figure 1 of report | :heavy_exclamation_mark: |
| Healthy Places | Road Safety | :x: | :x: | :x: | :x: - data unavailable | :x: |
| Healthy Places | Road Safety | 2023 | [PSNI](https://www.psni.police.uk/about-us/our-publications-and-reports/official-statistics/road-traffic-collision-statistics)| [OGL3](https://www.ninis2.nisra.gov.uk/public/terms.aspx) | :heavy_check_mark: Number of people seriously injured or killed by Local Authority area. | :heavy_check_mark: |
| Healthy Places | Road Traffic Volume | :x: | :x: | :x: | :x: Indicator not overtly present in England's Health Index. To review at the end. | :x: |
| Healthy Places | Internet access | :x: | :x: | :x: | :x: TO DO | :x: |
| Healthy Places | Transport noise: Daytime | 2017 | [NISRA](https://www.ninis2.nisra.gov.uk) | [OGL3](https://www.ninis2.nisra.gov.uk/public/terms.aspx) | :x: Indicator not overtly present in England's Health Index. To review at the end. | :x: |
Expand Down