Title: | Query the 'NHS TRUD API' |
---|---|
Description: | Provides a convenient R interface to the 'National Health Service NHS Technology Reference Update Distribution (TRUD) API', allowing users to list available releases for their subscribed items, retrieve metadata, and download release files. For more information on the API, see <https://isd.digital.nhs.uk/trud/users/guest/filters/0/api>. |
Authors: | Alasdair Warwick [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-0800-2890>), Robert Luben [aut] (ORCID: <https://orcid.org/0000-0002-5088-6343>), Abraham Olvera-Barrios [aut] (ORCID: <https://orcid.org/0000-0002-3305-4465>), Chuin Ying Ung [aut] (ORCID: <https://orcid.org/0000-0001-8487-4589>), Jon Clayden [rev] (ORCID: <https://orcid.org/0000-0002-6608-0619>), Alexandros Kouretsis [rev] |
Maintainer: | Alasdair Warwick <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0.9000 |
Built: | 2025-08-19 07:21:38 UTC |
Source: | https://github.com/ropensci/trud |
Downloads files for a specified NHS TRUD item. By default this downloads
the latest release. Use the item
numbers from trud_items()
or
get_subscribed_metadata()
.
Subscription Required
You must subscribe to TRUD items individually through the NHS TRUD website
before you can access them using get_item_metadata()
or download_item()
.
Simply having an API key is not sufficient. To see items you're already
subscribed to, use get_subscribed_metadata()
. To browse all available
items, use trud_items()
.
download_item( item, directory = ".", file_type = c("archive", "checksum", "signature", "publicKey"), release = NULL, overwrite = FALSE )
download_item( item, directory = ".", file_type = c("archive", "checksum", "signature", "publicKey"), release = NULL, overwrite = FALSE )
item |
An integer, the item to be downloaded. Get these from |
directory |
Path to the directory to which this item will be downloaded to. This is set to the current working directory by default. |
file_type |
The type of file to download. Options are |
release |
The release ID to be downloaded. Release IDs are found in the
|
overwrite |
If |
The file path to the downloaded file, returned invisibly.
To download a specific (non-latest) release:
Use get_item_metadata()
with release_scope = "all"
to retrieve metadata for all releases
The release IDs are stored under the id
item for each release
Pass the desired release ID to the release
parameter of download_item()
trud_items()
to find item numbers
get_subscribed_metadata()
to see items you can access
get_item_metadata()
to explore available releases before downloading
# Download Community Services Data Set pre-deadline extract XML Schema x <- download_item(394, directory = tempdir()) # List downloaded files unzip(x, list = TRUE) # Download a previous release # First get all releases to see available options metadata <- get_item_metadata(394, release_scope = "all") release_id <- metadata$releases[[2]]$id y <- download_item(394, directory = tempdir(), release = release_id) unzip(y, list = TRUE) # Overwrite existing files if needed z <- download_item(394, directory = tempdir(), overwrite = TRUE) # An informative error is raised if your API key is invalid or missing try(withr::with_envvar(c("TRUD_API_KEY" = ""), download_item(394)))
# Download Community Services Data Set pre-deadline extract XML Schema x <- download_item(394, directory = tempdir()) # List downloaded files unzip(x, list = TRUE) # Download a previous release # First get all releases to see available options metadata <- get_item_metadata(394, release_scope = "all") release_id <- metadata$releases[[2]]$id y <- download_item(394, directory = tempdir(), release = release_id) unzip(y, list = TRUE) # Overwrite existing files if needed z <- download_item(394, directory = tempdir(), overwrite = TRUE) # An informative error is raised if your API key is invalid or missing try(withr::with_envvar(c("TRUD_API_KEY" = ""), download_item(394)))
Sends a request to the release list endpoint, returning a list of metadata
pertaining to the specified NHS TRUD item. Use the item
numbers from
trud_items()
or get_subscribed_metadata()
.
Subscription Required
You must subscribe to TRUD items individually through the NHS TRUD website
before you can access them using get_item_metadata()
or download_item()
.
Simply having an API key is not sufficient. To see items you're already
subscribed to, use get_subscribed_metadata()
. To browse all available
items, use trud_items()
.
get_item_metadata(item, release_scope = c("all", "latest"))
get_item_metadata(item, release_scope = c("all", "latest"))
item |
An integer, the item to be downloaded. Get these from |
release_scope |
Which releases to retrieve metadata for. Use |
A list containing item metadata, including release information that
can be used with download_item()
. Release IDs for specific downloads are
in the id
field of each release.
trud_items()
to find item numbers
get_subscribed_metadata()
to see items you can access
download_item()
to download files using this metadata
# Get metadata for Community Services Data Set pre-deadline extract XML Schema get_item_metadata(394) |> # Display structure without showing sensitive API keys in URLs purrr::map_at("releases", \(release) purrr::map(release, names)) # Include metadata for any previous releases using `release_scope = "all"` get_item_metadata(394, release_scope = "all") |> # Display structure without showing sensitive API keys in URLs purrr::map_at("releases", \(release) purrr::map(release, names)) # An informative error is raised if your API key is invalid or missing try(withr::with_envvar(c("TRUD_API_KEY" = ""), get_item_metadata(394)))
# Get metadata for Community Services Data Set pre-deadline extract XML Schema get_item_metadata(394) |> # Display structure without showing sensitive API keys in URLs purrr::map_at("releases", \(release) purrr::map(release, names)) # Include metadata for any previous releases using `release_scope = "all"` get_item_metadata(394, release_scope = "all") |> # Display structure without showing sensitive API keys in URLs purrr::map_at("releases", \(release) purrr::map(release, names)) # An informative error is raised if your API key is invalid or missing try(withr::with_envvar(c("TRUD_API_KEY" = ""), get_item_metadata(394)))
A convenience wrapper around trud_items()
and get_item_metadata()
,
retrieving metadata for only items that the user is subscribed to. This is
particularly useful for seeing what data you can download with download_item()
.
If you need access to additional items, browse available options with
trud_items()
, then subscribe through the NHS TRUD website.
get_subscribed_metadata(release_scope = c("all", "latest"))
get_subscribed_metadata(release_scope = c("all", "latest"))
release_scope |
Which releases to retrieve metadata for. Use |
A tibble, with item metadata stored in the list column metadata
.
Use the item_number
column values with download_item()
.
trud_items()
to browse all available items
get_item_metadata()
for detailed metadata on specific items
download_item()
to download items you're subscribed to
# Get metadata for all subscribed items subscribed <- get_subscribed_metadata() # Show structure without exposing API keys in URLs subscribed$metadata[[1]] |> purrr::map_at("releases", \(release) purrr::map(release, names))
# Get metadata for all subscribed items subscribed <- get_subscribed_metadata() # Show structure without exposing API keys in URLs subscribed$metadata[[1]] |> purrr::map_at("releases", \(release) purrr::map(release, names))
Scrapes this page
from the NHS TRUD website for all available items. The item_number
column
in the result contains the identifiers you need for get_item_metadata()
and download_item()
.
Subscription Required
You must subscribe to TRUD items individually through the NHS TRUD website
before you can access them using get_item_metadata()
or download_item()
.
Simply having an API key is not sufficient. To see items you're already
subscribed to, use get_subscribed_metadata()
. To browse all available
items, use trud_items()
.
trud_items()
trud_items()
A tibble, with columns item_number
and item_name
. Use the
item_number
values as arguments to get_item_metadata()
and download_item()
.
get_subscribed_metadata()
to see only items you're subscribed to
get_item_metadata()
to get detailed information about a specific item
download_item()
to download files for a specific item
trud_items()
trud_items()