| match_tag | R Documentation |
Downloads and processes the UK Department for Transport TAG Data Book table RAS4001, and joins estimated collision costs to STATS19 data.
Three matching modes are available:
"severity" — cost varies only by collision severity
"severity_road" — cost varies by severity and road type
"severity_road_bua" — cost varies by severity & road type, where road
type is determined using ONS Built-Up Area (BUA) polygons (2022)
BUA polygons are downloaded automatically from: https://open-geography-portalx-ons.hub.arcgis.com/api/download/v1/items/ad30b234308f4b02b4bb9b0f4766f7bb/geoPackage?layers=0
Optionally, total costs may be summarised by severity and/or road type.
match_tag(
crashes,
shapes_url =
paste0("https://open-geography-portalx-ons.hub.arcgis.com/api/download/v1/",
"items/ad30b234308f4b02b4bb9b0f4766f7bb/geoPackage?layers=0"),
costs_url = paste0("https://assets.publishing.service.gov.uk/media/",
"68d421cc275fc9339a248c8e/ras4001.ods"),
match_with = "severity",
include_motorway_bua = FALSE,
summarise = FALSE
)
crashes |
A STATS19 collision data frame. May be |
shapes_url |
URL to download the ONS Built-Up Areas geopackage. Defaults to the official ONS 2022 dataset. |
costs_url |
URL to download the TAG Data Book RAS4001 table (ODS format). Defaults to the Department for Transport asset link. |
match_with |
Character string specifying the matching mode. One of:
The default uses |
include_motorway_bua |
Logical; if |
summarise |
Logical; if |
The function:
Downloads and parses RAS4001 cost tables
Computes road type using STATS19 fields or optional BUA polygons
Joins appropriate cost estimates
Optionally aggregates totals
When crashes is an sf object and summarise = TRUE, geometry is
automatically dropped.
A data frame (or sf object if input is sf) with added columns for
estimated collision costs.
If summarise = TRUE, a summary table of total costs (in millions) is returned.
## Not run:
# Simple severity-based matching
match_tag(stats19_df, match_with = "severity")
# Severity + road type
match_tag(stats19_df, match_with = "severity_road")
# Using ONS Built-Up Areas, with motorway override
match_tag(
stats19_df,
match_with = "severity_road_bua",
include_motorway_bua = TRUE
)
# Summarised totals
match_tag(stats19_df, match_with = "severity", summarise = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.