Skip to contents

Fetches the street, outcomes and stop-and-search CSV files for chosen months and forces from one or more archive snapshots, without downloading the whole zip: the zip's table of contents is read with an HTTP byte-range request and each wanted file is then fetched by range and inflated locally. Files already present in the cache with a matching checksum are skipped. Each fetched file is recorded with its CRC32 from the archive, a SHA-256 of its content and the time of download, which is what the panel contract reports as provenance.

Usage

lamp_archive_download(
  archives = "latest",
  months = NULL,
  forces = NULL,
  file_types = c("street", "outcomes", "stop-and-search"),
  dir = lamp_cache_dir(),
  index = NULL,
  relist = FALSE
)

Arguments

archives

Archive identifiers such as c("2026-06", "2026-07"), or "latest" (the default) for the newest snapshot in lamp_archive_index().

months

Months to fetch as "YYYY-MM" strings or Dates; NULL for every month in the archive.

forces

police.uk force identifiers such as "west-yorkshire"; NULL for every force. See lamp_forces().

file_types

Which of "street", "outcomes" and "stop-and-search" to fetch.

dir

Cache directory; see lamp_cache_dir().

index

An archive index from lamp_archive_index(), to avoid fetching it again.

relist

Read the archive's table of contents again even if it has been listed before.

Value

A lamp_snapshot (see lamp_archive_snapshot()) for dir, invisibly.

Examples

# \donttest{
# Needs network access. Fetches the latest month for one force into a
# temporary directory, and prints a message instead of failing when offline.
cache <- tempfile("streetlamp-")
snap <- tryCatch(
  {
    idx <- lamp_archive_index(dir = cache)
    lamp_archive_download(
      months = format(max(idx$to), "%Y-%m"), forces = "dyfed-powys",
      dir = cache, index = idx
    )
  },
  streetlamp_error_network = function(e) message(conditionMessage(e))
)
#> Network access is disabled by `STREETLAMP_OFFLINE`.
#> ℹ Could not fetch https://data.police.uk/data/archive/.
snap
#> NULL
# }