Skip to content

Commit

Permalink
Updated nearest neighbours to allow inputs for 153, 201, and 202
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Fox committed Nov 18, 2019
1 parent 0cfbd5c commit 2957d8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions R/area_types.R
Expand Up @@ -191,7 +191,7 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID, path) {
#' @return A character vector of area codes
#' @param AreaTypeID AreaTypeID of the nearest neighbours (see
#' \code{\link{area_types}}) for IDs. Only returns information on AreaTypeIDs
#' 101, 102, 152, and 154
#' 101, 102, 201, 202, 152, 153 and 154
#' @param measure string; when AreaTypeID = 102 measure must be either "CIPFA"
#' for CIPFA local authority nearest neighbours or "CSSN" for Children's
#' services statistical neighbours
Expand Down Expand Up @@ -224,14 +224,20 @@ nearest_neighbours <- function(AreaCode, AreaTypeID = 101, measure, path) {
if (missing(measure)) measure <- NA
if (AreaTypeID == 101) {
val <- 1
} else if (AreaTypeID == 154) {
} else if (AreaTypeID == 153) {
val <- 2
} else if (AreaTypeID == 102 & measure == "CSSN") {
val <- 3
} else if (AreaTypeID == 102 & measure == "CIPFA") {
val <- 1
} else if (AreaTypeID == 152) {
val <- 4
} else if (AreaTypeID == 154) {
val <- 6
} else if (AreaTypeID == 202) {
val <- 7
} else if (AreaTypeID == 201) {
val <- 7
} else {
val <- NA
}
Expand All @@ -247,7 +253,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID = 101, measure, path) {
unlist(use.names = FALSE)
areacheck <- areacheck[grepl("^E", areacheck)]
if (!(AreaCode %in% areacheck)) stop(paste0(AreaCode, " not in AreaTypeID = ", AreaTypeID))
if (is.na(val)) stop("AreaTypeID must be one of 101, 102, 152 or 154")
if (is.na(val)) stop("AreaTypeID must be one of 101, 102, 201, 202, 152, 153 or 154")
path <- paste0(path,
sprintf("areas/by_parent_area_code?area_type_id=%s&parent_area_code=nn-%s-%s",
AreaTypeID, val, AreaCode))
Expand Down
2 changes: 1 addition & 1 deletion man/nearest_neighbours.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-area_types.R
Expand Up @@ -51,7 +51,7 @@ test_that("nearest_neighbours returns as expected", {
skip_if_offline()
expect_is(nearest_neighbours(AreaCode = "E38000002", AreaTypeID = 154), "character")
skip_if_offline()
expect_error(nearest_neighbours(AreaCode = "E12000001", AreaTypeID = 6), "AreaTypeID must be one of 101, 102, 152 or 154")
expect_error(nearest_neighbours(AreaCode = "E12000001", AreaTypeID = 6), "AreaTypeID must be one of 101, 102, 201, 202, 152, 153 or 154")
skip_if_offline()
expect_error(nearest_neighbours(AreaCode = "E07000033", AreaTypeID = 152), "E07000033 not in AreaTypeID = 152")
skip_if_offline()
Expand Down

0 comments on commit 2957d8f

Please sign in to comment.