Skip to content

Commit

Permalink
Merge pull request #115 from ropensci/proxy_settings
Browse files Browse the repository at this point in the history
Proxy settings
  • Loading branch information
annabelwestermann96 authored Feb 14, 2024
2 parents caa9b7b + 901aa66 commit a27146e
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 52 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: fingertipsR
Type: Package
Version: 1.0.10.9002
Version: 1.0.12
Title: Fingertips Data for Public Health
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.
Maintainer: Annabel Westermann <annabel.westermann@dhsc.gov.uk>
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")),
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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()`
Expand Down
15 changes: 8 additions & 7 deletions R/area_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion R/deprivation_decile.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
2 changes: 1 addition & 1 deletion R/enhancements.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/fingertips_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions R/indicator_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions R/indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/profiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion R/retrieve_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 34 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions man/area_types.Rd

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

5 changes: 3 additions & 2 deletions man/category_types.Rd

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

10 changes: 8 additions & 2 deletions man/deprivation_decile.Rd

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

5 changes: 3 additions & 2 deletions man/fingertips_data.Rd

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

5 changes: 3 additions & 2 deletions man/fingertips_stats.Rd

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

2 changes: 1 addition & 1 deletion man/get_fingertips_api.Rd

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

10 changes: 8 additions & 2 deletions man/indicator_areatypes.Rd

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

5 changes: 3 additions & 2 deletions man/indicator_metadata.Rd

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

Loading

0 comments on commit a27146e

Please sign in to comment.