Skip to content

Commit fb48519

Browse files
authored
Merge pull request #130 from ropensci/dev
Dev
2 parents db13aba + 91a21da commit fb48519

23 files changed

+140
-158
lines changed

‎DESCRIPTION‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: fingertipsR
22
Type: Package
3-
Version: 1.0.13
3+
Version: 1.1.0
44
Title: Fingertips Data for Public Health
55
Description: Fingertips (<http://fingertips.phe.org.uk/>) contains data for many indicators of public health in England. The underlying data is now more easily accessible by making use of the API.
66
Maintainer: Sam Dunn <[email protected]>
@@ -17,6 +17,7 @@ Authors@R: c(
1717
person("David", "Whiting", , "[email protected]", c("ctb")),
1818
person("Luke", "Bradley", , "[email protected]", c("ctb")),
1919
person("Samuel", "Cutler", , "[email protected]", c("ctb")),
20+
person("Thilaksan", "Vikneswaran", , "[email protected]", c("ctb")),
2021
person("Crown Copyright 2020", , , , c("cph")))
2122
URL: https://fingertips.phe.org.uk,
2223
https://github.com/ropensci/fingertipsR,

‎NEWS.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# fingertipsR 1.1.0 (2025-10-10)
2+
3+
* Updated the description of the nearest_neighbours function, and removed the measure variable that was previously deprecated.
4+
* Added checks to handle cases where no data is available for the specified combination of parameters in `fingertips_data()`.
5+
* When no data is available and `rank = TRUE`, the function now returns an empty data frame with `Polarity`, `Rank`, and `AreaValuesCount` columns set to `NA`.
6+
* Improved error message to inform users that no data is available and an empty data frame is returned.
7+
* Updated examples.
8+
* Updated area_types() function to use the short name in the API rather than the long name
9+
110
# fingertipsR 1.0.13 (2025-05-29)
211

312
* no change for users. Package tests updated.

‎R/area_types.R‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
#' area_types()
2020
#'
2121
#' # Returns a data frame of county and unitary authority mappings
22-
#' area_types("counties")
22+
#' area_types("counties")
2323
#'
2424
#' # Returns a data frame of both counties, district
2525
#' # and unitary authorities and their respective mappings
26-
#' areas <- c("counties","district")
26+
#' areas <- c("counties", "district")
2727
#' area_types(areas)
2828
#'
2929
#' # Uses AreaTypeID to filter area types
30-
#' area_types(AreaTypeID = 152)}
30+
#' area_types(AreaTypeID = 7)}
3131
#' @import dplyr
3232
#' @importFrom stats complete.cases
3333
#' @importFrom rlang .data
@@ -55,7 +55,7 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL
5555
proxy_settings = proxy_settings)
5656
parentAreas <- paste0(path,"area_types/parent_area_types") %>%
5757
get_fingertips_api(proxy_settings = proxy_settings)
58-
area_types <- parentAreas[,c("Id", "Name")]
58+
area_types <- parentAreas[,c("Id", "Short")]
5959
names(area_types) <- c("AreaTypeID","AreaTypeName")
6060
parentAreasNoNames <- parentAreas$ParentAreaTypes
6161
names(parentAreasNoNames) <- parentAreas$Id
@@ -65,7 +65,7 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL
6565
select(
6666
AreaTypeID = "t",
6767
ParentAreaTypeID = "Id",
68-
ParentAreaTypeName = "Name") %>%
68+
ParentAreaTypeName = "Short") %>%
6969
mutate(AreaTypeID = as.numeric(.data$AreaTypeID),
7070
ParentAreaTypeID = as.numeric(.data$ParentAreaTypeID))
7171
area_types <- left_join(area_types, parentAreas, by = c("AreaTypeID" = "AreaTypeID")) %>%
@@ -153,7 +153,7 @@ category_types <- function(proxy_settings = fingertips_proxy_settings(),
153153
#' @import dplyr
154154
#' @examples
155155
#' \dontrun{
156-
#' indicator_areatypes(IndicatorID = 10101)}
156+
#' indicator_areatypes(IndicatorID = 90362)}
157157
#' @export
158158
#' @family lookup functions
159159
#' @seealso \code{\link{indicators}} for indicator lookups,
@@ -196,35 +196,38 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID,
196196

197197
#' Nearest neighbours
198198
#'
199-
#' Outputs a character vector of similar areas for given area. Currently returns
200-
#' similar areas for Clinical Commissioning Groups (old and new) based on
201-
#' \href{https://www.england.nhs.uk/publication/similar-10-ccg-explorer-tool/}{NHS
202-
#' England's similar CCG explorer tool} or lower and upper tier local
203-
#' authorities based on
199+
#' Outputs a character vector of similar areas for a given area.\cr\cr**Details**\cr
200+
#' - For new upper tier local authorities (post 4/23) the
201+
#' \href{https://github.com/NHSDigital/ASC_LA_Peer_Groups}{NHSE Nearest Neighbours
202+
#' Model} is used.
203+
#' - All other local authorities types (lower tier and older upper tier) use the
204204
#' \href{https://www.cipfastats.net/resources/nearestneighbours/}{CIPFA's
205-
#' Nearest Neighbours Model} or upper tier local authorities based on
205+
#' Nearest Neighbours Model}. Older local authority geography types will use
206+
#' older versions of the model.
207+
#' - Similar areas for Clinical Commissioning Groups are based on
208+
#' \href{https://www.england.nhs.uk/publication/similar-10-ccg-explorer-tool/}{NHS
209+
#' England's similar CCG explorer tool}.
210+
#' - Currently the function does not have the ability to use the method from the
206211
#' \href{https://www.gov.uk/government/publications/local-authority-interactive-tool-lait}{Children's
207-
#' services statistical neighbour benchmarking tool}
212+
#' services statistical neighbour benchmarking tool}.
213+
#' @md
208214
#'
209215
#' @return A character vector of area codes
210216
#' @param AreaTypeID AreaTypeID of the nearest neighbours (see
211217
#' \code{\link{nearest_neighbour_areatypeids}}) for available IDs
212-
#' @param measure deprecated. Previously a string; when AreaTypeID = 102 measure
213-
#' must be either "CIPFA" for CIPFA local authority nearest neighbours or
214-
#' "CSSN" for Children's services statistical neighbours
215218
#' @inheritParams fingertips_data
216219
#' @inheritParams area_types
217220
#' @import dplyr
218221
#' @importFrom utils head
219222
#' @importFrom rlang .data
220223
#' @examples
221224
#' \dontrun{
222-
#' nearest_neighbours(AreaCode = "E38000002", AreaTypeID = 154)}
225+
#' nearest_neighbours(AreaCode = "E09000004", AreaTypeID = 502)}
223226
#' @export
224227
#' @family lookup functions
225228
#' @seealso \code{\link{nearest_neighbour_areatypeids}} for the AreaTypeIDs
226229
#' available for this function
227-
nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
230+
nearest_neighbours <- function(AreaCode, AreaTypeID,
228231
proxy_settings = fingertips_proxy_settings(), path) {
229232

230233
if (missing(path)) path <- fingertips_endpoint()
@@ -264,10 +267,6 @@ nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
264267
stop("AreaTypeID not found. Use function `nearest_neighbour_areatypeids()` to see available AreaTypeIDs.")
265268
}
266269

267-
if (!(missing(measure))) {
268-
warning("Measure argument is now deprecated.")
269-
}
270-
271270
ParentAreaTypeID <- area_types(AreaTypeID = AreaTypeID) %>%
272271
pull("ParentAreaTypeID") %>%
273272
head(1)

‎R/deprivation_decile.R‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#' @inheritParams area_types
1717
#' @examples
1818
#' \dontrun{
19-
#' # Return 2019 deprivation scores for Sustainability and Transformation Footprints
20-
#' deprivation_decile(120, 2019)}
19+
#' # Return 2019 deprivation scores for Upper tier local authorities (post 4/23)
20+
#' deprivation_decile(502, 2019)}
2121
#' @return A lookup table providing deprivation decile and area code
2222
#' @import dplyr
2323
#' @importFrom rlang .data

‎R/enhancements.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' @examples
1414
#' \dontrun{
1515
#' # Returns data for the two selected domains at county and unitary authority geography
16-
#' reddata <- fingertips_redred(ProfileID = 26, AreaTypeID = 102)}
16+
#' reddata <- fingertips_redred(ProfileID = 26, AreaTypeID = 502)}
1717
#' @family data extract functions
1818
#' @export
1919

‎R/fingertipsR.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
#' @section Data extract functions: Using ID codes as inputs, the data extract
1111
#' functions allow the user to extract data from the Fingertips API.
1212
#'
13-
#' @docType package
13+
#' @docType _PACKAGE
1414
#' @name fingertipsR
1515
NULL

‎R/fingertips_data.R‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#' @details Note, polarity of an indicator is not automatically returned (eg,
99
#' whether a low value is good, bad or neither). Use the rank field for this
1010
#' to be returned (though it adds a lot of time to the query)
11+
#'
12+
#' Some indicators may have different comparisons due to indicator polarity differences between profiles on the website.
13+
#' It is recommended to check the website to ensure consistency between your data extract here and the polarity required
1114
#' @inheritParams indicators
1215
#' @param IndicatorID Numeric vector, id of the indicator of interest
1316
#' @param ProfileID Numeric vector, id of profiles of interest. Indicator
@@ -38,24 +41,14 @@
3841
#' \dontrun{
3942
#' # Returns data for the two selected domains at county and unitary authority geography
4043
#' doms <- c(1000049,1938132983)
41-
#' fingdata <- fingertips_data(DomainID = doms, AreaTypeID = 202)
44+
#' fingdata <- fingertips_data(DomainID = doms, AreaTypeID = 502)
4245
#'
43-
#' # Returns data at local authority district geography (AreaTypeID = 101)
46+
#' # Returns data at local authority district geography (AreaTypeID = 501)
4447
#' # for the indicator with the id 22401
45-
#' fingdata <- fingertips_data(22401, AreaTypeID = 101)
46-
#'
47-
#' # Returns same indicator with different comparisons due to indicator polarity
48-
#' # differences between profiles on the website
49-
#' # It is recommended to check the website to ensure consistency between your
50-
#' # data extract here and the polarity required
51-
#' fingdata <- fingertips_data(rep(90282,2),
52-
#' ProfileID = c(19,93),
53-
#' AreaTypeID = 202,
54-
#' AreaCode = "E06000008")
55-
#' fingdata <- fingdata[order(fingdata$TimeperiodSortable, fingdata$Sex),]
48+
#' fingdata <- fingertips_data(22401, AreaTypeID = 501)
5649
#'
5750
#' # Returns data for all available area types for an indicator
58-
#' fingdata <- fingertips_data(10101, AreaTypeID = "All")}
51+
#' fingdata <- fingertips_data(90362, AreaTypeID = "All")}
5952
#' @family data extract functions
6053
#' @export
6154

@@ -112,7 +105,6 @@ fingertips_data <- function(IndicatorID = NULL,
112105
if (!(categorytype %in% c(TRUE, FALSE))){
113106
stop("categorytype input must be TRUE or FALSE")
114107
}
115-
116108
# check on area details before calling data
117109
if (is.null(AreaTypeID)) {
118110
stop("AreaTypeID must have a value. Use function area_types() to see what values can be used.")
@@ -340,8 +332,22 @@ fingertips_data <- function(IndicatorID = NULL,
340332
}
341333

342334
}
335+
336+
343337
names(fingertips_data) <- gsub("\\s","",names(fingertips_data))
344338

339+
if (nrow(fingertips_data) == 0) {
340+
warning("No data available for the specified combination of parameters. Returning an empty data frame.")
341+
if (rank == TRUE) {
342+
required_columns <- c(names(fingertips_data), "Polarity", "Rank", "AreaValuesCount")
343+
fingertips_data <- data.frame(matrix(ncol = length(required_columns), nrow = 0))
344+
colnames(fingertips_data) <- required_columns
345+
fingertips_data <- fingertips_data %>%
346+
mutate(Polarity = character(), Rank = integer(), AreaValuesCount = integer())
347+
return(fingertips_data)
348+
}
349+
}
350+
345351
if (rank == TRUE) {
346352
inds <- unique(fingertips_data$IndicatorID)
347353
if (!is.null(ProfileID)) {
@@ -351,14 +357,12 @@ fingertips_data <- function(IndicatorID = NULL,
351357
proxy_settings = proxy_settings,
352358
path = path) %>%
353359
select(.data$IndicatorID, .data$Polarity)
354-
355360
} else {
356361
polarities <- indicator_metadata(
357362
inds,
358363
proxy_settings = proxy_settings,
359364
path = path) %>%
360365
select("IndicatorID", "Polarity")
361-
362366
}
363367
fingertips_data <- left_join(fingertips_data, polarities, by = c("IndicatorID" = "IndicatorID")) %>%
364368
group_by(.data$IndicatorID,
@@ -371,8 +375,10 @@ fingertips_data <- function(IndicatorID = NULL,
371375
mutate(Rank = rank(.data$Value, na.last = "keep"),
372376
AreaValuesCount = sum(!is.na(.data$Value))) %>%
373377
ungroup()
374-
375378
}
379+
380+
381+
376382
if (!is.null(AreaCode)) {
377383
fingertips_data <- fingertips_data[fingertips_data$AreaCode %in% AreaCode,] %>%
378384
droplevels()

‎R/indicator_metadata.R‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#' @inheritParams area_types
99
#' @examples
1010
#' \dontrun{
11-
#' # Returns metadata for indicator ID 90362 and 1107
12-
#' indicatorIDs <- c(90362, 1107)
11+
#' # Returns metadata for indicator ID 90362 and 92901
12+
#' indicatorIDs <- c(90362, 92901)
1313
#' indicator_metadata(indicatorIDs)
1414
#'
15-
#' # Returns metadata for the indicators within the domain 1000101
16-
#' indicator_metadata(DomainID = 1000101)
15+
#' # Returns metadata for the indicators within the domain 1000049
16+
#' indicator_metadata(DomainID = 1000049)
1717
#'
18-
#' # Returns metadata for the indicators within the profile with the ID 129
19-
#' indicator_metadata(ProfileID = 129)}
18+
#' # Returns metadata for the indicators within the profile with the ID 19
19+
#' indicator_metadata(ProfileID = 19)}
2020
#' @return The metadata associated with each indicator/domain/profile identified
2121
#' @importFrom utils read.csv
2222
#' @importFrom readr read_csv cols
@@ -157,8 +157,8 @@ indicator_metadata <- function(IndicatorID = NULL,
157157
#' @inheritParams area_types
158158
#' @examples
159159
#' \dontrun{
160-
#' # Returns metadata for indicator ID 90362 and 1107
161-
#' indicatorIDs <- c(90362, 1107)
160+
#' # Returns metadata for indicator ID 90362 and 92901
161+
#' indicatorIDs <- c(90362, 92901)
162162
#' indicator_update_information(indicatorIDs)}
163163
#' @return The date of latest data update for selected indicators
164164
#' @importFrom rlang .data

‎R/indicators.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ indicators_unique <- function(ProfileID = NULL,
139139
#' @importFrom rlang .data
140140
#' @examples
141141
#' \dontrun{
142-
#' indicator_order(DomainID = 1938133161, AreaTypeID = 102, ParentAreaTypeID = 6)}
142+
#' indicator_order(DomainID = 1000049, AreaTypeID = 502, ParentAreaTypeID = 6)}
143143
#' @family lookup functions
144144
#' @seealso \code{\link{indicators}} for indicators and their parent domains and profiles,
145145
#' \code{\link{area_types}} for area type and their parent mappings,

‎man/area_types.Rd‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)