diff --git a/DESCRIPTION b/DESCRIPTION
index f34a885..cdce93f 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: fingertipsR
Type: Package
-Version: 1.0.10.9002
+Version: 1.0.12
Title: Fingertips Data for Public Health
Description: Fingertips () contains data for many indicators of public health in England. The underlying data is now more easily accessible by making use of the API.
Maintainer: Annabel Westermann
@@ -8,6 +8,7 @@ Depends: R (>= 3.4.0)
Authors@R: c(
person("Annabel", "Westermann", , "annabel.westermann@dhsc.gov.uk", c("aut", "cre")),
person("Sebastian", "Fox", , "sebsfox@gmail.com", c("aut", "ctb")),
+ person("Hadley", "Nanayakkara", , "hadley.nanayakkara@dhsc.gov.uk", c("aut", "ctb")),
person("Julian", "Flowers", , , c("aut","ctb")),
person("Simon", "Thelwall", , "simon.thelwall@ukhsa.gov.uk", c("ctb"),
comment = c(ORCID = "0000-0002-0434-2724")),
@@ -42,5 +43,5 @@ VignetteBuilder: knitr
License: GPL-3
Encoding: UTF-8
LazyData: true
-RoxygenNote: 7.2.1
+RoxygenNote: 7.2.3
Config/testthat/edition: 3
diff --git a/NEWS.md b/NEWS.md
index 74a85e9..7e3ab06 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,8 @@
-# fingertipsR 1.0.10.9001
+# fingertipsR 1.0.12 (2023-17-11)
+
+* Automatically detects proxy settings in each function.
+
+# fingertipsR 1.0.11 (2023-09-11)
* Provision of ability to turn off automatic proxy settings using internet explorer's settings using `proxy_settings` argument
* bug fix to allow `rank = TRUE` when multiple ProfileIDs and IndicatorIDs passed to `fingertips_data()`
diff --git a/R/area_types.R b/R/area_types.R
index 4e4c00e..b93cd1b 100644
--- a/R/area_types.R
+++ b/R/area_types.R
@@ -10,7 +10,8 @@
#' @param AreaTypeID Numeric vector, the Fingertips ID for the area type;
#' default is NULL
#' @param proxy_settings string; whether to use Internet Explorer proxy settings
-#' ("default") or "none"
+#' "default" or "none". Setting this manually will decrease runtime;
+#' default determined automatically.
#' @inheritParams indicators
#' @examples
#' \dontrun{
@@ -43,7 +44,7 @@
#' Fingertips website within a Domain
area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL,
- proxy_settings = "default", path){
+ proxy_settings = fingertips_proxy_settings(), path){
if (!(is.null(AreaTypeName)) & !(is.null(AreaTypeID))) {
warning("AreaTypeName used when both AreaTypeName and AreaTypeID are entered")
}
@@ -118,7 +119,7 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL
#' \code{\link{indicator_order}} for the order indicators are presented on the
#' Fingertips website within a Domain
-category_types <- function(proxy_settings = "default",
+category_types <- function(proxy_settings = fingertips_proxy_settings(),
path) {
if (missing(path)) path <- fingertips_endpoint()
set_config(config(ssl_verifypeer = 0L))
@@ -165,7 +166,7 @@ category_types <- function(proxy_settings = "default",
#' \code{\link{indicator_order}} for the order indicators are presented on the
#' Fingertips website within a Domain
indicator_areatypes <- function(IndicatorID, AreaTypeID,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
if (missing(path)) path <- fingertips_endpoint()
fingertips_ensure_api_available(
endpoint = path,
@@ -224,7 +225,7 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID,
#' @seealso \code{\link{nearest_neighbour_areatypeids}} for the AreaTypeIDs
#' available for this function
nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
if (missing(path)) path <- fingertips_endpoint()
fingertips_ensure_api_available(
@@ -292,7 +293,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
}
areas_by_profile <- function(AreaTypeID, ProfileID,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
set_config(config(ssl_verifypeer = 0L))
fingertips_ensure_api_available(
endpoint = path,
@@ -346,7 +347,7 @@ areas_by_profile <- function(AreaTypeID, ProfileID,
#' @examples
#' \dontrun{
#' nearest_neighbour_areatypeids()}
-nearest_neighbour_areatypeids <- function(proxy_settings = "default") {
+nearest_neighbour_areatypeids <- function(proxy_settings = fingertips_proxy_settings()) {
url <- "https://fingertips.phe.org.uk/api/nearest_neighbour_types"
diff --git a/R/deprivation_decile.R b/R/deprivation_decile.R
index c72d3d5..7ae9c61 100644
--- a/R/deprivation_decile.R
+++ b/R/deprivation_decile.R
@@ -35,7 +35,7 @@
#' presented on the Fingertips website within a Domain
deprivation_decile <- function(AreaTypeID, Year = 2019,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
if (missing(AreaTypeID)) stop("AreaTypeID must be specified")
if (!(Year %in% c(2015, 2019))) {
diff --git a/R/enhancements.R b/R/enhancements.R
index 5ed95e9..6bb18e3 100644
--- a/R/enhancements.R
+++ b/R/enhancements.R
@@ -54,7 +54,7 @@ fingertips_redred <- function(Comparator = "England", ...) {
#' # Returns a sentence describing number of indicators and profiles in Fingertips
#' fingertips_stats()}
#' @export
-fingertips_stats <- function(proxy_settings = "default") {
+fingertips_stats <- function(proxy_settings = fingertips_proxy_settings()) {
fingertips_stats <- indicators(proxy_settings = proxy_settings)
summarised_stats <- fingertips_stats %>%
summarise_if(is.integer, n_distinct)
diff --git a/R/fingertips_data.R b/R/fingertips_data.R
index 61c8aa7..2bdd6a8 100644
--- a/R/fingertips_data.R
+++ b/R/fingertips_data.R
@@ -68,7 +68,7 @@ fingertips_data <- function(IndicatorID = NULL,
categorytype = FALSE,
rank = FALSE,
url_only = FALSE,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path) {
if (missing(path)) path <- fingertips_endpoint()
diff --git a/R/indicator_metadata.R b/R/indicator_metadata.R
index 9f315b9..3af1650 100644
--- a/R/indicator_metadata.R
+++ b/R/indicator_metadata.R
@@ -37,7 +37,7 @@
indicator_metadata <- function(IndicatorID = NULL,
DomainID = NULL,
ProfileID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path) {
set_config(config(ssl_verifypeer = 0L))
types <- cols(`Indicator ID` = "i",
@@ -165,7 +165,7 @@ indicator_metadata <- function(IndicatorID = NULL,
#' @export
indicator_update_information <- function(IndicatorID, ProfileID = NULL,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
if (missing(path)) path <- fingertips_endpoint()
set_config(config(ssl_verifypeer = 0L))
diff --git a/R/indicators.R b/R/indicators.R
index e27e101..16c4edd 100644
--- a/R/indicators.R
+++ b/R/indicators.R
@@ -31,7 +31,7 @@
indicators <- function(ProfileID = NULL,
DomainID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path) {
if (missing(path)) path <- fingertips_endpoint()
set_config(config(ssl_verifypeer = 0L))
@@ -112,7 +112,7 @@ indicators <- function(ProfileID = NULL,
#' @export
indicators_unique <- function(ProfileID = NULL,
DomainID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path) {
if (missing(path)) path <- fingertips_endpoint()
fingertips_ensure_api_available(
@@ -153,7 +153,7 @@ indicators_unique <- function(ProfileID = NULL,
indicator_order <- function(DomainID,
AreaTypeID,
ParentAreaTypeID,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path) {
if (missing(DomainID)|missing(AreaTypeID)|missing(ParentAreaTypeID))
stop("All of DomainID, AreaTypeID and ParentAreaTypeID are required")
diff --git a/R/profiles.R b/R/profiles.R
index bdd11bd..5398ed1 100644
--- a/R/profiles.R
+++ b/R/profiles.R
@@ -30,7 +30,7 @@
#' @export
profiles <- function(ProfileID = NULL, ProfileName = NULL,
- proxy_settings = "default", path) {
+ proxy_settings = fingertips_proxy_settings(), path) {
if (missing(path)) path <- fingertips_endpoint()
set_config(config(ssl_verifypeer = 0L))
fingertips_ensure_api_available(
diff --git a/R/retrieve_data.R b/R/retrieve_data.R
index 9760526..5478a4a 100644
--- a/R/retrieve_data.R
+++ b/R/retrieve_data.R
@@ -103,7 +103,7 @@ retrieve_profile <- function(ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, pa
#' @importFrom stats setNames
new_data_formatting <- function(dataurl, generic_name = FALSE,
item_of_total, progress_bar,
- proxy_settings = "default") {
+ proxy_settings = fingertips_proxy_settings()) {
proxy_settings <- match.arg(
proxy_settings,
diff --git a/R/utils.R b/R/utils.R
index 6723c0e..28aab71 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -16,7 +16,7 @@
#' "/area/parent_areas?child_area_code=E12000005&parent_area_type_ids=15"))
get_fingertips_api <- function(api_path, content_type = "text",
col_types,
- proxy_settings = "default") {
+ proxy_settings = fingertips_proxy_settings()) {
match.arg(proxy_settings,
c("default",
"none"))
@@ -97,7 +97,7 @@ fingertips_endpoint <- function() default_api
#' @return \code{TRUE} if the API is available, otherwise \code{stop()} is called.
#' @noRd
fingertips_ensure_api_available <- function(endpoint = fingertips_endpoint(),
- proxy_settings = "default") {
+ proxy_settings = fingertips_proxy_settings()) {
code <- FALSE
endpoint <- gsub("/api/", "", endpoint)
@@ -137,3 +137,35 @@ fingertips_deframe <- function(data) {
.Names = data[[1]])
return(out)
}
+
+
+#' fingertips_proxy_settings
+#' @description determines which proxy settings are used
+#' @return A character string with the proxy settings
+#' @noRd
+fingertips_proxy_settings <- function() {
+
+ # First try using default as proxy settings
+ fingertips_proxy <- "default"
+ errtext <- tryCatch(
+ {
+ fingertips_ensure_api_available(proxy_settings = "default")
+ }, error=function(e) {"The API is currently unavailable."}
+ )
+
+ # Second try using "none" as proxy settings
+ if (errtext != TRUE) {
+ fingertips_proxy <- "none"
+ errtext <- tryCatch(
+ {
+ fingertips_ensure_api_available(proxy_settings = "none")
+ }, error=function(e) {"The API is currently unavailable."}
+ )
+
+ # Stop if neither settings work
+ if (errtext != TRUE) {
+ stop(paste(errtext, collapse='\n '), call. = FALSE)
+ }
+ }
+ return(fingertips_proxy)
+}
diff --git a/man/area_types.Rd b/man/area_types.Rd
index f02b4eb..4041572 100644
--- a/man/area_types.Rd
+++ b/man/area_types.Rd
@@ -8,7 +8,7 @@ area_types(
AreaTypeName = NULL,
AreaTypeID = NULL,
ProfileID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -22,7 +22,8 @@ default is NULL}
\item{ProfileID}{Numeric vector, id of profiles of interest}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/category_types.Rd b/man/category_types.Rd
index d59807d..4835e07 100644
--- a/man/category_types.Rd
+++ b/man/category_types.Rd
@@ -4,11 +4,12 @@
\alias{category_types}
\title{Category types}
\usage{
-category_types(proxy_settings = "default", path)
+category_types(proxy_settings = fingertips_proxy_settings(), path)
}
\arguments{
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/deprivation_decile.Rd b/man/deprivation_decile.Rd
index 4bb32d3..ba83924 100644
--- a/man/deprivation_decile.Rd
+++ b/man/deprivation_decile.Rd
@@ -4,7 +4,12 @@
\alias{deprivation_decile}
\title{Deprivation deciles}
\usage{
-deprivation_decile(AreaTypeID, Year = 2019, proxy_settings = "default", path)
+deprivation_decile(
+ AreaTypeID,
+ Year = 2019,
+ proxy_settings = fingertips_proxy_settings(),
+ path
+)
}
\arguments{
\item{AreaTypeID}{Integer value; this function uses the IndicatorIDs 91872,
@@ -15,7 +20,8 @@ see what AreaTypeIDs are available}
applied, limited to 2015 or 2019}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/fingertips_data.Rd b/man/fingertips_data.Rd
index 78f28dc..898da14 100644
--- a/man/fingertips_data.Rd
+++ b/man/fingertips_data.Rd
@@ -14,7 +14,7 @@ fingertips_data(
categorytype = FALSE,
rank = FALSE,
url_only = FALSE,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -52,7 +52,8 @@ are returned also in AreaValuesCount}
character vector}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/fingertips_stats.Rd b/man/fingertips_stats.Rd
index 7eec98b..785bf8e 100644
--- a/man/fingertips_stats.Rd
+++ b/man/fingertips_stats.Rd
@@ -4,11 +4,12 @@
\alias{fingertips_stats}
\title{High level statistics on Fingertips data}
\usage{
-fingertips_stats(proxy_settings = "default")
+fingertips_stats(proxy_settings = fingertips_proxy_settings())
}
\arguments{
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
}
\value{
A string that summarises the high level statistics of indicators and
diff --git a/man/get_fingertips_api.Rd b/man/get_fingertips_api.Rd
index 987bd75..c1ef1bb 100644
--- a/man/get_fingertips_api.Rd
+++ b/man/get_fingertips_api.Rd
@@ -8,7 +8,7 @@ get_fingertips_api(
api_path,
content_type = "text",
col_types,
- proxy_settings = "default"
+ proxy_settings = fingertips_proxy_settings()
)
}
\arguments{
diff --git a/man/indicator_areatypes.Rd b/man/indicator_areatypes.Rd
index b41797e..7d03903 100644
--- a/man/indicator_areatypes.Rd
+++ b/man/indicator_areatypes.Rd
@@ -4,7 +4,12 @@
\alias{indicator_areatypes}
\title{Area types by indicator}
\usage{
-indicator_areatypes(IndicatorID, AreaTypeID, proxy_settings = "default", path)
+indicator_areatypes(
+ IndicatorID,
+ AreaTypeID,
+ proxy_settings = fingertips_proxy_settings(),
+ path
+)
}
\arguments{
\item{IndicatorID}{integer; the Indicator ID (can be ignored or of length 1).
@@ -13,7 +18,8 @@ Takes priority over AreaTypeID if both are entered}
\item{AreaTypeID}{integer; the Area Type ID (can be ignored or of length 1)}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/indicator_metadata.Rd b/man/indicator_metadata.Rd
index c412aa2..f1e9e7c 100644
--- a/man/indicator_metadata.Rd
+++ b/man/indicator_metadata.Rd
@@ -8,7 +8,7 @@ indicator_metadata(
IndicatorID = NULL,
DomainID = NULL,
ProfileID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -24,7 +24,8 @@ IndicatorID is populated, ProfileID can be ignored or must be the same
length as IndicatorID (but can contain NAs).}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/indicator_order.Rd b/man/indicator_order.Rd
index 91254ef..da59054 100644
--- a/man/indicator_order.Rd
+++ b/man/indicator_order.Rd
@@ -8,7 +8,7 @@ indicator_order(
DomainID,
AreaTypeID,
ParentAreaTypeID,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -24,7 +24,8 @@ extracted; if NULL the function will use the first record for the specified
`AreaTypeID` from the area_types() function}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/indicator_update_information.Rd b/man/indicator_update_information.Rd
index 2fcb382..57e92fa 100644
--- a/man/indicator_update_information.Rd
+++ b/man/indicator_update_information.Rd
@@ -7,7 +7,7 @@
indicator_update_information(
IndicatorID,
ProfileID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -17,7 +17,8 @@ indicator_update_information(
\item{ProfileID}{Integer (optional), whether to restrict the indicators to a particular profile}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/indicators.Rd b/man/indicators.Rd
index 3b327eb..e66b70c 100644
--- a/man/indicators.Rd
+++ b/man/indicators.Rd
@@ -4,7 +4,12 @@
\alias{indicators}
\title{Live indicators and the profiles and domains they belong to}
\usage{
-indicators(ProfileID = NULL, DomainID = NULL, proxy_settings = "default", path)
+indicators(
+ ProfileID = NULL,
+ DomainID = NULL,
+ proxy_settings = fingertips_proxy_settings(),
+ path
+)
}
\arguments{
\item{ProfileID}{Numeric vector, id of profiles of interest}
@@ -12,7 +17,8 @@ indicators(ProfileID = NULL, DomainID = NULL, proxy_settings = "default", path)
\item{DomainID}{Numeric vector, id of domains of interest}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/indicators_unique.Rd b/man/indicators_unique.Rd
index 24ca9c3..76b62a5 100644
--- a/man/indicators_unique.Rd
+++ b/man/indicators_unique.Rd
@@ -7,7 +7,7 @@
indicators_unique(
ProfileID = NULL,
DomainID = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -17,7 +17,8 @@ indicators_unique(
\item{DomainID}{Numeric vector, id of domains of interest}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/nearest_neighbour_areatypeids.Rd b/man/nearest_neighbour_areatypeids.Rd
index 02d55b6..82ff84b 100644
--- a/man/nearest_neighbour_areatypeids.Rd
+++ b/man/nearest_neighbour_areatypeids.Rd
@@ -4,11 +4,12 @@
\alias{nearest_neighbour_areatypeids}
\title{Nearest neighbours area type ids}
\usage{
-nearest_neighbour_areatypeids(proxy_settings = "default")
+nearest_neighbour_areatypeids(proxy_settings = fingertips_proxy_settings())
}
\arguments{
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
}
\value{
table of AreaTypeIDs
diff --git a/man/nearest_neighbours.Rd b/man/nearest_neighbours.Rd
index 1567eea..b41dd18 100644
--- a/man/nearest_neighbours.Rd
+++ b/man/nearest_neighbours.Rd
@@ -8,7 +8,7 @@ nearest_neighbours(
AreaCode,
AreaTypeID,
measure,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -23,7 +23,8 @@ must be either "CIPFA" for CIPFA local authority nearest neighbours or
"CSSN" for Children's services statistical neighbours}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/man/profiles.Rd b/man/profiles.Rd
index 33db185..16c5376 100644
--- a/man/profiles.Rd
+++ b/man/profiles.Rd
@@ -7,7 +7,7 @@
profiles(
ProfileID = NULL,
ProfileName = NULL,
- proxy_settings = "default",
+ proxy_settings = fingertips_proxy_settings(),
path
)
}
@@ -17,7 +17,8 @@ profiles(
\item{ProfileName}{Character vector, full name of profile(s)}
\item{proxy_settings}{string; whether to use Internet Explorer proxy settings
-("default") or "none"}
+"default" or "none". Setting this manually will decrease runtime;
+ default determined automatically.}
\item{path}{String; Fingertips API address. Function will default to the
correct address}
diff --git a/tests/testthat/test-area_types.R b/tests/testthat/test-area_types.R
index e58580c..d08b757 100644
--- a/tests/testthat/test-area_types.R
+++ b/tests/testthat/test-area_types.R
@@ -87,7 +87,7 @@ test_that("category_types returns 5 column table", {
category_types(
proxy_settings = "none"
)),
- 5,
+ 6,
info = "testing the function with proxy_settings = 'none'")
})