| Title: | Download Data on UK Police and Crime |
|---|---|
| Description: | Downloads data from the 'UK Police' public data API, the full docs of which are available at <https://data.police.uk/docs/>. Includes data on police forces and police force areas, crime reports, and the use of stop-and-search powers. |
| Authors: | Evan Odell [aut, cre] (ORCID: <https://orcid.org/0000-0003-1845-808X>), Nicholas Tierney [aut] (ORCID: <https://orcid.org/0000-0003-1460-8722>) |
| Maintainer: | Evan Odell <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.2.9001 |
| Built: | 2026-05-20 08:26:48 UTC |
| Source: | https://github.com/evanodell/ukpolice |
Downloads data from the 'UK Police' public data API. Includes data on UK police forces and police force areas, crime reports, and the use of stop-and-search powers.
Most functions return a tibble with the requested data, with the exception
of ukc_specific_outcome() in some cases, which returns a list containing a
list and a tibble.
Data accessed through ukpolice is licenced with
Open Government Licence v3.0.
The API allows for 15 requests each second, but up to 30 in a single second if in a single burst. The API does not require authentication. See the API documentation for more details.
Returns a tibble with all available datasets. The id column contains the
year and month, and other columns contain a list with all police forces
reporting data for that month. As of 2019-04-02 only information on
stop and search data is returned by this endpoint.
ukc_available()ukc_available()
Crime categories
ukc_crime_category()ukc_crime_category()
A tibble with all available categories of crime.
Returns details of crimes within a one mile radius of a given point, at a specific location ID, or from within a custom polygon.
ukc_crime_loc(location, date = NULL, ...) ukc_crime_coord(lat, lng, date = NULL, ...) ukc_crime_poly(poly_df, date = NULL, ...) ukc_crime_location(lat, lng, location, date = NULL, ...)ukc_crime_loc(location, date = NULL, ...) ukc_crime_coord(lat, lng, date = NULL, ...) ukc_crime_poly(poly_df, date = NULL, ...) ukc_crime_location(lat, lng, location, date = NULL, ...)
location |
If specified, |
date |
The year and month in "YYYY-MM" form. If |
... |
further arguments passed to |
lat |
Latitude. Accepts a single value. |
lng |
Longitude. Accepts a single value. |
poly_df |
a dataframe containing the lat/lng pairs which define
the boundary of the custom area, or a |
If specified, lat and lng must be the same length. location
or both lat and lng must be specified.
A tibble with details of crimes at a given location.
The API will return a 400 status code in response to a GET request longer than 4094 characters.
## Not run: x <- ukc_crime_location(lat = 52, lng = 0) y <- ukc_crime_location(location = 802171) poly_df_3 <- data.frame( lat = c(52.268, 52.794, 52.130), lng = c(0.543, 0.238, 0.478) ) z <- ukc_crime_poly(poly_df_3) ## End(Not run)## Not run: x <- ukc_crime_location(lat = 52, lng = 0) y <- ukc_crime_location(location = 802171) poly_df_3 <- data.frame( lat = c(52.268, 52.794, 52.130), lng = c(0.543, 0.238, 0.478) ) z <- ukc_crime_poly(poly_df_3) ## End(Not run)
Returns details of crimes that cannot be mapped to a particular location. Note that the police force must be specified.
ukc_crime_no_location(force, crime_category = NULL, date = NULL)ukc_crime_no_location(force, crime_category = NULL, date = NULL)
force |
A string containing the name of the police force to return data for. Must be specified, and is not case sensitive. |
crime_category |
The category of crime to return. Defaults to
returning all crimes. See |
date |
The year and month in "YYYY-MM" form. If |
A tibble with details of crimes without a specific location.
## Not run: no_location <- ukc_crime_no_location(force = "city-of-london") ## End(Not run)## Not run: no_location <- ukc_crime_no_location(force = "city-of-london") ## End(Not run)
Returns available police forces, details on a specific police force, or officers on that force.
ukc_forces() ukc_force_details(force = NULL) ukc_officers(force)ukc_forces() ukc_force_details(force = NULL) ukc_officers(force)
force |
The id of the police force, available from the |
ukc_forces returns a tibble with all police forces in England
and Wales, ukc_force_details returns details on a given police force and
ukc_officers returns details on senior officers for a given police force.
## Not run: forces <- ukc_forces() cops <- ukc_officers("cumbria") details <- ukc_force_details("thames-valley") ## End(Not run)## Not run: forces <- ukc_forces() cops <- ukc_officers("cumbria") details <- ukc_force_details("thames-valley") ## End(Not run)
Returns the latest month crime data was updated for. The date is in standard ISO format but the actual day is not relevant.
ukc_last_update()ukc_last_update()
Data on a specific neighbourhood boundary, using lat/lng pairs.
ukc_neighbourhood_boundary(force, neighbourhood_id)ukc_neighbourhood_boundary(force, neighbourhood_id)
force |
A string containing the name of the police force to return neighbourhoods for. Must be specified, and is not case sensitive. |
neighbourhood_id |
A string containing the ID of a given neighbourhood,
returned from |
A tibble with the lat/lng boundaries for a specific neighbourhood.
## Not run: borders <- ukc_neighbourhood_boundary("dorset", "55.CR3001") ## End(Not run)## Not run: borders <- ukc_neighbourhood_boundary("dorset", "55.CR3001") ## End(Not run)
Find the neighbourhood policing team responsible for a given area, by a set of coordinates. Accepts only a single pair of latitude and longitude.
ukc_neighbourhood_location(lat, lng)ukc_neighbourhood_location(lat, lng)
lat |
Latitude |
lng |
Longitude |
The police force and neighbourhood code of the given coordinates.
## Not run: find <- ukc_neighbourhood_location(lat = 51.500617, lng = -0.124629) ## End(Not run)## Not run: find <- ukc_neighbourhood_location(lat = 51.500617, lng = -0.124629) ## End(Not run)
Data on a specific neighbourhood within a given police force area.
ukc_neighbourhood_specific(force, neighbourhood_id) ukc_neighbourhood_events(force, neighbourhood_id) ukc_neighbourhood_priorities(force, neighbourhood_id) ukc_neighbourhood_team(force, neighbourhood_id)ukc_neighbourhood_specific(force, neighbourhood_id) ukc_neighbourhood_events(force, neighbourhood_id) ukc_neighbourhood_priorities(force, neighbourhood_id) ukc_neighbourhood_team(force, neighbourhood_id)
force |
A string containing the name of the police force to return neighbourhoods for. Must be specified, and is not case sensitive. |
neighbourhood_id |
A string containing the ID of a given neighbourhood,
returned from |
ukpolice contains the following functions for specific neighbourhoods:
ukc_neighbourhood_specific – Basic information and description of a
specific neighbourhood.
ukc_neighbourhood_team – Brief biographies of police officers
responsible for the specified neighbourhood.
ukc_neighbourhood_events – Police public engagement events taking
place in the specified neighbourhood.
ukc_neighbourhood_priorities – Policing priorities for the
specified neighbourhood.
A list with data for a specific neighbourhood, or a tibble with all neighbourhood IDs if no neighbourhood is specified.
## Not run: # returns a specific neighbourood places4 <- ukc_neighbourhood_specific("dorset", "55.CR3001") # returns all neighbourhoods as specific neighbourhood is unspecified. places3 <- ukc_neighbourhood_specific("dorset") ## End(Not run) ## Not run: events <- ukc_neighbourhood_events("dorset", "55.CR3001") ## End(Not run) ## Not run: priorities <- ukc_neighbourhood_team("dorset", "55.CR3001") ## End(Not run) ## Not run: people <- ukc_neighbourhood_team("dorset", "55.CR3001") ## End(Not run)## Not run: # returns a specific neighbourood places4 <- ukc_neighbourhood_specific("dorset", "55.CR3001") # returns all neighbourhoods as specific neighbourhood is unspecified. places3 <- ukc_neighbourhood_specific("dorset") ## End(Not run) ## Not run: events <- ukc_neighbourhood_events("dorset", "55.CR3001") ## End(Not run) ## Not run: priorities <- ukc_neighbourhood_team("dorset", "55.CR3001") ## End(Not run) ## Not run: people <- ukc_neighbourhood_team("dorset", "55.CR3001") ## End(Not run)
All the neighbourhoods within a given police force area.
ukc_neighbourhoods(force)ukc_neighbourhoods(force)
force |
A string containing the name of the police force to return neighbourhoods for. Must be specified, and is not case sensitive. |
A tibble with data for neighbourhoods within the area of the
given police force.
## Not run: places <- ukc_neighbourhoods("dorset") ## End(Not run)## Not run: places <- ukc_neighbourhoods("dorset") ## End(Not run)
Returns the outcomes (case history) for a specified crime.
The ID of a crime is a 64-character string, named persistent_id and
returned by other methods.
ukc_specific_outcome(persistent_id)ukc_specific_outcome(persistent_id)
persistent_id |
The 64 character string that is the unique ID of a particular crime. |
Either a tibble with basic details of a crime if no outcome
is available, or a list with basic details and a tibble containing
the outcome if one is available.
## Not run: no_location <- ukc_crime_no_location(force = "city-of-london") crime_id <- no_location$persistent_id[[1]] outcome <- ukc_specific_outcome(crime_id) ## End(Not run)## Not run: no_location <- ukc_crime_no_location(force = "city-of-london") crime_id <- no_location$persistent_id[[1]] outcome <- ukc_specific_outcome(crime_id) ## End(Not run)
Returns details of stop and searches carried out by a particular police force. Note that the police force must be specified.
ukc_stop_search_force(force, date = NULL)ukc_stop_search_force(force, date = NULL)
force |
A string containing the name of the police force to return data
for. Must be specified, and is not case sensitive.
See |
date |
The year and month in "YYYY-MM" form. Also accepts dates in
formats that can be coerced to |
A tibble with details of stop and searches by a given police force.
## Not run: ss_dorset <- ukc_stop_search_force(force = "dorset") ## End(Not run)## Not run: ss_dorset <- ukc_stop_search_force(force = "dorset") ## End(Not run)
Returns details on stops and searches at a given location. The stop and searches returned in the API, like the crimes, are only an approximation of where the actual stop and searches occurred, they are not the exact locations.
ukc_stop_search_loc(location, date = NULL, ...) ukc_stop_search_coord(lat, lng, date = NULL, ...) ukc_stop_search_poly(poly_df, date = NULL, ...) ukc_stop_search_location(lat, lng, location, date = NULL)ukc_stop_search_loc(location, date = NULL, ...) ukc_stop_search_coord(lat, lng, date = NULL, ...) ukc_stop_search_poly(poly_df, date = NULL, ...) ukc_stop_search_location(lat, lng, location, date = NULL)
location |
If specified, |
date |
The year and month in "YYYY-MM" form. If |
... |
further arguments passed to |
lat |
Latitude. Accepts a single value or a vector of values to create a custom polygon. |
lng |
Longitude. Accepts a single value or a vector of values to create a custom polygon. |
poly_df |
a dataframe containing the lat/lng pairs which define
the boundary of the custom area, or a |
Functions accept one of lat and lng pairs, location IDs or
a dataframe containing lat/lng pairs defining the boundary of a custom area.
If specified, lat and lng must be the same length. If only one
set of coordinates are given, all recorded stop and searches within a one
mile radius are returned. If multiple pairs, all recorded stop and searches
within a custom drawn polygon will be returned.
A tibble with details of stop and searches outcomes.
## Not run: ukc_stop_search2 <- ukc_stop_search_coord( lat = c(52.268, 53.194, 52.130), lng = c(0.543, 0.238, 0.478) ) poly_df_4 <- data.frame( lat = c(52.268, 52.794, 52.130, 52.000), long = c(0.543, 0.238, 0.478, 0.400) ) ukc_data_poly_4 <- ukc_stop_search_poly(poly_df = poly_df_4) ## End(Not run)## Not run: ukc_stop_search2 <- ukc_stop_search_coord( lat = c(52.268, 53.194, 52.130), lng = c(0.543, 0.238, 0.478) ) poly_df_4 <- data.frame( lat = c(52.268, 52.794, 52.130, 52.000), long = c(0.543, 0.238, 0.478, 0.400) ) ukc_data_poly_4 <- ukc_stop_search_poly(poly_df = poly_df_4) ## End(Not run)
Returns details of stop and searches that cannot be mapped to a particular
location. Note that the police force must be specified. For all stop and
searches carried out by a police force, use ukc_stop_search_force().
ukc_stop_search_no_location(force, date = NULL)ukc_stop_search_no_location(force, date = NULL)
force |
A string containing the name of the police force to return data
for. Must be specified, and is not case sensitive.
See |
date |
The year and month in "YYYY-MM" form. Also accepts dates in
formats that can be coerced to |
A tibble with details of stop and searches without a specific
location.
## Not run: ss_no_location <- ukc_stop_search_no_location(force = "city-of-london") ## End(Not run)## Not run: ss_no_location <- ukc_stop_search_no_location(force = "city-of-london") ## End(Not run)
Street level crime
ukc_street_crime(lat, lng, date = NULL, crime_category = NULL)ukc_street_crime(lat, lng, date = NULL, crime_category = NULL)
lat |
Latitude. Accepts a single value or a vector of values to create a custom polygon. |
lng |
Longitude. Accepts a single value or a vector of values to create a custom polygon. |
date |
The year and month in "YYYY-MM" form. If |
crime_category |
The category of crime to return. Defaults to
returning all crimes. See |
lat and lng must be the same length.
A tibble with details of street crimes.
## Not run: crime <- ukc_street_crime( lat = 51.5, lng = -0.6, crime_category = "bicycle-theft" ) crime_poly <- ukc_street_crime( lat = c(52.268, 52.794, 52.130), lng = c(0.543, 0.238, 0.478) ) ## End(Not run)## Not run: crime <- ukc_street_crime( lat = 51.5, lng = -0.6, crime_category = "bicycle-theft" ) crime_poly <- ukc_street_crime( lat = c(52.268, 52.794, 52.130), lng = c(0.543, 0.238, 0.478) ) ## End(Not run)
Returns details on crimes at a given location, if given the id of a specific location. If given latitude and longitude, finds the nearest pre-defined location and returns the crimes which occurred there.
ukc_street_crime_outcome(lat, lng, location, date = NULL)ukc_street_crime_outcome(lat, lng, location, date = NULL)
lat |
Latitude. Accepts a single value or a vector of values to create a custom polygon. |
lng |
Longitude. Accepts a single value or a vector of values to create a custom polygon. |
location |
If specified, |
date |
The year and month in "YYYY-MM" form. If |
If specified, lat and lng must be the same length. location
or both lat and lng must be specified.
A tibble with details of street crime outcomes.
## Not run: street_crime_outcome1 <- ukc_street_crime_outcome(location = 883498) street_crime_outcome2 <- ukc_street_crime_outcome(lat = 52, lng = 0) ## End(Not run)## Not run: street_crime_outcome1 <- ukc_street_crime_outcome(location = 883498) street_crime_outcome2 <- ukc_street_crime_outcome(lat = 52, lng = 0) ## End(Not run)