Skip to content

Commit a27146e

Browse files
Merge pull request #115 from ropensci/proxy_settings
Proxy settings
2 parents caa9b7b + 901aa66 commit a27146e

27 files changed

+119
-52
lines changed

DESCRIPTION

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Package: fingertipsR
22
Type: Package
3-
Version: 1.0.10.9002
3+
Version: 1.0.12
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: Annabel Westermann <[email protected]>
77
Depends: R (>= 3.4.0)
88
Authors@R: c(
99
person("Annabel", "Westermann", , "[email protected]", c("aut", "cre")),
1010
person("Sebastian", "Fox", , "[email protected]", c("aut", "ctb")),
11+
person("Hadley", "Nanayakkara", , "[email protected]", c("aut", "ctb")),
1112
person("Julian", "Flowers", , , c("aut","ctb")),
1213
person("Simon", "Thelwall", , "[email protected]", c("ctb"),
1314
comment = c(ORCID = "0000-0002-0434-2724")),
@@ -42,5 +43,5 @@ VignetteBuilder: knitr
4243
License: GPL-3
4344
Encoding: UTF-8
4445
LazyData: true
45-
RoxygenNote: 7.2.1
46+
RoxygenNote: 7.2.3
4647
Config/testthat/edition: 3

NEWS.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# fingertipsR 1.0.10.9001
1+
# fingertipsR 1.0.12 (2023-17-11)
2+
3+
* Automatically detects proxy settings in each function.
4+
5+
# fingertipsR 1.0.11 (2023-09-11)
26

37
* Provision of ability to turn off automatic proxy settings using internet explorer's settings using `proxy_settings` argument
48
* bug fix to allow `rank = TRUE` when multiple ProfileIDs and IndicatorIDs passed to `fingertips_data()`

R/area_types.R

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#' @param AreaTypeID Numeric vector, the Fingertips ID for the area type;
1111
#' default is NULL
1212
#' @param proxy_settings string; whether to use Internet Explorer proxy settings
13-
#' ("default") or "none"
13+
#' "default" or "none". Setting this manually will decrease runtime;
14+
#' default determined automatically.
1415
#' @inheritParams indicators
1516
#' @examples
1617
#' \dontrun{
@@ -43,7 +44,7 @@
4344
#' Fingertips website within a Domain
4445

4546
area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL,
46-
proxy_settings = "default", path){
47+
proxy_settings = fingertips_proxy_settings(), path){
4748
if (!(is.null(AreaTypeName)) & !(is.null(AreaTypeID))) {
4849
warning("AreaTypeName used when both AreaTypeName and AreaTypeID are entered")
4950
}
@@ -118,7 +119,7 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL
118119
#' \code{\link{indicator_order}} for the order indicators are presented on the
119120
#' Fingertips website within a Domain
120121

121-
category_types <- function(proxy_settings = "default",
122+
category_types <- function(proxy_settings = fingertips_proxy_settings(),
122123
path) {
123124
if (missing(path)) path <- fingertips_endpoint()
124125
set_config(config(ssl_verifypeer = 0L))
@@ -165,7 +166,7 @@ category_types <- function(proxy_settings = "default",
165166
#' \code{\link{indicator_order}} for the order indicators are presented on the
166167
#' Fingertips website within a Domain
167168
indicator_areatypes <- function(IndicatorID, AreaTypeID,
168-
proxy_settings = "default", path) {
169+
proxy_settings = fingertips_proxy_settings(), path) {
169170
if (missing(path)) path <- fingertips_endpoint()
170171
fingertips_ensure_api_available(
171172
endpoint = path,
@@ -224,7 +225,7 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID,
224225
#' @seealso \code{\link{nearest_neighbour_areatypeids}} for the AreaTypeIDs
225226
#' available for this function
226227
nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
227-
proxy_settings = "default", path) {
228+
proxy_settings = fingertips_proxy_settings(), path) {
228229

229230
if (missing(path)) path <- fingertips_endpoint()
230231
fingertips_ensure_api_available(
@@ -292,7 +293,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID, measure,
292293
}
293294

294295
areas_by_profile <- function(AreaTypeID, ProfileID,
295-
proxy_settings = "default", path) {
296+
proxy_settings = fingertips_proxy_settings(), path) {
296297
set_config(config(ssl_verifypeer = 0L))
297298
fingertips_ensure_api_available(
298299
endpoint = path,
@@ -346,7 +347,7 @@ areas_by_profile <- function(AreaTypeID, ProfileID,
346347
#' @examples
347348
#' \dontrun{
348349
#' nearest_neighbour_areatypeids()}
349-
nearest_neighbour_areatypeids <- function(proxy_settings = "default") {
350+
nearest_neighbour_areatypeids <- function(proxy_settings = fingertips_proxy_settings()) {
350351

351352
url <- "https://fingertips.phe.org.uk/api/nearest_neighbour_types"
352353

R/deprivation_decile.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#' presented on the Fingertips website within a Domain
3636

3737
deprivation_decile <- function(AreaTypeID, Year = 2019,
38-
proxy_settings = "default", path) {
38+
proxy_settings = fingertips_proxy_settings(), path) {
3939
if (missing(AreaTypeID)) stop("AreaTypeID must be specified")
4040

4141
if (!(Year %in% c(2015, 2019))) {

R/enhancements.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fingertips_redred <- function(Comparator = "England", ...) {
5454
#' # Returns a sentence describing number of indicators and profiles in Fingertips
5555
#' fingertips_stats()}
5656
#' @export
57-
fingertips_stats <- function(proxy_settings = "default") {
57+
fingertips_stats <- function(proxy_settings = fingertips_proxy_settings()) {
5858
fingertips_stats <- indicators(proxy_settings = proxy_settings)
5959
summarised_stats <- fingertips_stats %>%
6060
summarise_if(is.integer, n_distinct)

R/fingertips_data.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fingertips_data <- function(IndicatorID = NULL,
6868
categorytype = FALSE,
6969
rank = FALSE,
7070
url_only = FALSE,
71-
proxy_settings = "default",
71+
proxy_settings = fingertips_proxy_settings(),
7272
path) {
7373

7474
if (missing(path)) path <- fingertips_endpoint()

R/indicator_metadata.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
indicator_metadata <- function(IndicatorID = NULL,
3838
DomainID = NULL,
3939
ProfileID = NULL,
40-
proxy_settings = "default",
40+
proxy_settings = fingertips_proxy_settings(),
4141
path) {
4242
set_config(config(ssl_verifypeer = 0L))
4343
types <- cols(`Indicator ID` = "i",
@@ -165,7 +165,7 @@ indicator_metadata <- function(IndicatorID = NULL,
165165
#' @export
166166

167167
indicator_update_information <- function(IndicatorID, ProfileID = NULL,
168-
proxy_settings = "default", path) {
168+
proxy_settings = fingertips_proxy_settings(), path) {
169169

170170
if (missing(path)) path <- fingertips_endpoint()
171171
set_config(config(ssl_verifypeer = 0L))

R/indicators.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
indicators <- function(ProfileID = NULL,
3333
DomainID = NULL,
34-
proxy_settings = "default",
34+
proxy_settings = fingertips_proxy_settings(),
3535
path) {
3636
if (missing(path)) path <- fingertips_endpoint()
3737
set_config(config(ssl_verifypeer = 0L))
@@ -112,7 +112,7 @@ indicators <- function(ProfileID = NULL,
112112
#' @export
113113
indicators_unique <- function(ProfileID = NULL,
114114
DomainID = NULL,
115-
proxy_settings = "default",
115+
proxy_settings = fingertips_proxy_settings(),
116116
path) {
117117
if (missing(path)) path <- fingertips_endpoint()
118118
fingertips_ensure_api_available(
@@ -153,7 +153,7 @@ indicators_unique <- function(ProfileID = NULL,
153153
indicator_order <- function(DomainID,
154154
AreaTypeID,
155155
ParentAreaTypeID,
156-
proxy_settings = "default",
156+
proxy_settings = fingertips_proxy_settings(),
157157
path) {
158158
if (missing(DomainID)|missing(AreaTypeID)|missing(ParentAreaTypeID))
159159
stop("All of DomainID, AreaTypeID and ParentAreaTypeID are required")

R/profiles.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#' @export
3131

3232
profiles <- function(ProfileID = NULL, ProfileName = NULL,
33-
proxy_settings = "default", path) {
33+
proxy_settings = fingertips_proxy_settings(), path) {
3434
if (missing(path)) path <- fingertips_endpoint()
3535
set_config(config(ssl_verifypeer = 0L))
3636
fingertips_ensure_api_available(

R/retrieve_data.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ retrieve_profile <- function(ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, pa
103103
#' @importFrom stats setNames
104104
new_data_formatting <- function(dataurl, generic_name = FALSE,
105105
item_of_total, progress_bar,
106-
proxy_settings = "default") {
106+
proxy_settings = fingertips_proxy_settings()) {
107107

108108
proxy_settings <- match.arg(
109109
proxy_settings,

R/utils.R

+34-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' "/area/parent_areas?child_area_code=E12000005&parent_area_type_ids=15"))
1717
get_fingertips_api <- function(api_path, content_type = "text",
1818
col_types,
19-
proxy_settings = "default") {
19+
proxy_settings = fingertips_proxy_settings()) {
2020
match.arg(proxy_settings,
2121
c("default",
2222
"none"))
@@ -97,7 +97,7 @@ fingertips_endpoint <- function() default_api
9797
#' @return \code{TRUE} if the API is available, otherwise \code{stop()} is called.
9898
#' @noRd
9999
fingertips_ensure_api_available <- function(endpoint = fingertips_endpoint(),
100-
proxy_settings = "default") {
100+
proxy_settings = fingertips_proxy_settings()) {
101101
code <- FALSE
102102
endpoint <- gsub("/api/", "", endpoint)
103103

@@ -137,3 +137,35 @@ fingertips_deframe <- function(data) {
137137
.Names = data[[1]])
138138
return(out)
139139
}
140+
141+
142+
#' fingertips_proxy_settings
143+
#' @description determines which proxy settings are used
144+
#' @return A character string with the proxy settings
145+
#' @noRd
146+
fingertips_proxy_settings <- function() {
147+
148+
# First try using default as proxy settings
149+
fingertips_proxy <- "default"
150+
errtext <- tryCatch(
151+
{
152+
fingertips_ensure_api_available(proxy_settings = "default")
153+
}, error=function(e) {"The API is currently unavailable."}
154+
)
155+
156+
# Second try using "none" as proxy settings
157+
if (errtext != TRUE) {
158+
fingertips_proxy <- "none"
159+
errtext <- tryCatch(
160+
{
161+
fingertips_ensure_api_available(proxy_settings = "none")
162+
}, error=function(e) {"The API is currently unavailable."}
163+
)
164+
165+
# Stop if neither settings work
166+
if (errtext != TRUE) {
167+
stop(paste(errtext, collapse='\n '), call. = FALSE)
168+
}
169+
}
170+
return(fingertips_proxy)
171+
}

man/area_types.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/category_types.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/deprivation_decile.Rd

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fingertips_data.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fingertips_stats.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_fingertips_api.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/indicator_areatypes.Rd

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/indicator_metadata.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)