From 94812c4e2bef112231c6d1eeaf123278a5632501 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Thu, 9 Nov 2023 19:06:05 +0000 Subject: [PATCH 01/11] Added proxy settings on startup --- R/zzz.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 R/zzz.R diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..1a9b1c3 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,20 @@ +.onAttach <- function(libname, pkgname) { + assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) + + tryCatch( + { + fingertips_ensure_api_available(proxy_settings = "default") + }, error=function(e) { + assign("fingertips_proxy", "none", envir=as.environment("package:fingertipsR")) + tryCatch( + { + fingertips_ensure_api_available(proxy_settings = "none") + }, error=function(e) { + assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) + packageStartupMessage("The API is currently unavailable, you may need to reload the package when the API becomes available.") + } + ) + } + ) +} + From dd15ef366a3b78f852ac40f0744e092dec14ab03 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 10 Nov 2023 09:05:21 +0000 Subject: [PATCH 02/11] Changed proxy settings to use pre-determined variable. --- R/area_types.R | 12 ++++++------ R/deprivation_decile.R | 2 +- R/enhancements.R | 2 +- R/fingertips_data.R | 2 +- R/indicator_metadata.R | 4 ++-- R/indicators.R | 6 +++--- R/profiles.R | 2 +- R/retrieve_data.R | 2 +- R/utils.R | 4 ++-- R/zzz.R | 3 +-- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/R/area_types.R b/R/area_types.R index 4e4c00e..9d69681 100644 --- a/R/area_types.R +++ b/R/area_types.R @@ -43,7 +43,7 @@ #' Fingertips website within a Domain area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL, - proxy_settings = "default", path){ + proxy_settings = fingertips_proxy, path){ if (!(is.null(AreaTypeName)) & !(is.null(AreaTypeID))) { warning("AreaTypeName used when both AreaTypeName and AreaTypeID are entered") } @@ -118,7 +118,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, path) { if (missing(path)) path <- fingertips_endpoint() set_config(config(ssl_verifypeer = 0L)) @@ -165,7 +165,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, path) { if (missing(path)) path <- fingertips_endpoint() fingertips_ensure_api_available( endpoint = path, @@ -224,7 +224,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, path) { if (missing(path)) path <- fingertips_endpoint() fingertips_ensure_api_available( @@ -292,7 +292,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID, measure, } areas_by_profile <- function(AreaTypeID, ProfileID, - proxy_settings = "default", path) { + proxy_settings = fingertips_proxy, path) { set_config(config(ssl_verifypeer = 0L)) fingertips_ensure_api_available( endpoint = path, @@ -346,7 +346,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) { url <- "https://fingertips.phe.org.uk/api/nearest_neighbour_types" diff --git a/R/deprivation_decile.R b/R/deprivation_decile.R index c72d3d5..471e197 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, 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..12d2812 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) { 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..38d9fd3 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, path) { if (missing(path)) path <- fingertips_endpoint() diff --git a/R/indicator_metadata.R b/R/indicator_metadata.R index 9f315b9..0bab8d1 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, 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, 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..48623e4 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, 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, 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, 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..e03eea2 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, 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..18c5330 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) { proxy_settings <- match.arg( proxy_settings, diff --git a/R/utils.R b/R/utils.R index 6723c0e..4539889 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) { 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) { code <- FALSE endpoint <- gsub("/api/", "", endpoint) diff --git a/R/zzz.R b/R/zzz.R index 1a9b1c3..4c0e85f 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -11,10 +11,9 @@ fingertips_ensure_api_available(proxy_settings = "none") }, error=function(e) { assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) - packageStartupMessage("The API is currently unavailable, you may need to reload the package when the API becomes available.") + packageStartupMessage("The API is currently unavailable, you may need to reload fingertipsR when the API becomes available.") } ) } ) } - From 6471482a6848712d77db77e753675da011165fc0 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 10 Nov 2023 09:56:31 +0000 Subject: [PATCH 03/11] Updated docs. --- DESCRIPTION | 5 +++-- NEWS.md | 6 +++++- man/area_types.Rd | 2 +- man/category_types.Rd | 2 +- man/deprivation_decile.Rd | 7 ++++++- man/fingertips_data.Rd | 2 +- man/fingertips_stats.Rd | 2 +- man/get_fingertips_api.Rd | 2 +- man/indicator_areatypes.Rd | 7 ++++++- man/indicator_metadata.Rd | 2 +- man/indicator_order.Rd | 2 +- man/indicator_update_information.Rd | 2 +- man/indicators.Rd | 7 ++++++- man/indicators_unique.Rd | 2 +- man/nearest_neighbour_areatypeids.Rd | 2 +- man/nearest_neighbours.Rd | 2 +- man/profiles.Rd | 2 +- 17 files changed, 38 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f34a885..3b7bf9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fingertipsR Type: Package -Version: 1.0.10.9002 +Version: 1.0.11.9001 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", "cre")), 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..e020904 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# fingertipsR 1.0.10.9001 +# fingertipsR 1.0.11.9001 (2023-10-11) + +* Determines if automatic proxy settings using internet explorer's settings should be used on package load. + +# 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/man/area_types.Rd b/man/area_types.Rd index f02b4eb..6a9ba53 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, path ) } diff --git a/man/category_types.Rd b/man/category_types.Rd index d59807d..d3c644f 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -4,7 +4,7 @@ \alias{category_types} \title{Category types} \usage{ -category_types(proxy_settings = "default", path) +category_types(proxy_settings = fingertips_proxy, path) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/deprivation_decile.Rd b/man/deprivation_decile.Rd index 4bb32d3..ea072fb 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, + path +) } \arguments{ \item{AreaTypeID}{Integer value; this function uses the IndicatorIDs 91872, diff --git a/man/fingertips_data.Rd b/man/fingertips_data.Rd index 78f28dc..d49eece 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, path ) } diff --git a/man/fingertips_stats.Rd b/man/fingertips_stats.Rd index 7eec98b..e835165 100644 --- a/man/fingertips_stats.Rd +++ b/man/fingertips_stats.Rd @@ -4,7 +4,7 @@ \alias{fingertips_stats} \title{High level statistics on Fingertips data} \usage{ -fingertips_stats(proxy_settings = "default") +fingertips_stats(proxy_settings = fingertips_proxy) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/get_fingertips_api.Rd b/man/get_fingertips_api.Rd index 987bd75..33bb39e 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 ) } \arguments{ diff --git a/man/indicator_areatypes.Rd b/man/indicator_areatypes.Rd index b41797e..68118ef 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, + path +) } \arguments{ \item{IndicatorID}{integer; the Indicator ID (can be ignored or of length 1). diff --git a/man/indicator_metadata.Rd b/man/indicator_metadata.Rd index c412aa2..37d0184 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, path ) } diff --git a/man/indicator_order.Rd b/man/indicator_order.Rd index 91254ef..04e5582 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, path ) } diff --git a/man/indicator_update_information.Rd b/man/indicator_update_information.Rd index 2fcb382..da5d0e6 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, path ) } diff --git a/man/indicators.Rd b/man/indicators.Rd index 3b327eb..4179b90 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, + path +) } \arguments{ \item{ProfileID}{Numeric vector, id of profiles of interest} diff --git a/man/indicators_unique.Rd b/man/indicators_unique.Rd index 24ca9c3..3ce094d 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, path ) } diff --git a/man/nearest_neighbour_areatypeids.Rd b/man/nearest_neighbour_areatypeids.Rd index 02d55b6..5b3d0cf 100644 --- a/man/nearest_neighbour_areatypeids.Rd +++ b/man/nearest_neighbour_areatypeids.Rd @@ -4,7 +4,7 @@ \alias{nearest_neighbour_areatypeids} \title{Nearest neighbours area type ids} \usage{ -nearest_neighbour_areatypeids(proxy_settings = "default") +nearest_neighbour_areatypeids(proxy_settings = fingertips_proxy) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/nearest_neighbours.Rd b/man/nearest_neighbours.Rd index 1567eea..19741c9 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, path ) } diff --git a/man/profiles.Rd b/man/profiles.Rd index 33db185..ddf6cc2 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, path ) } From 9f0f3464f351d369d4dffa2ea22e3fc45f4b0ee1 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 10 Nov 2023 11:09:46 +0000 Subject: [PATCH 04/11] Updated test --- tests/testthat/test-area_types.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'") }) From ddf7a26e31db6b608ac06cccc9fbe2579bbf5d42 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 10 Nov 2023 11:11:47 +0000 Subject: [PATCH 05/11] Updated dsc --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3b7bf9a..c8c0780 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +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", "cre")), + 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")), From 5b2bf49c2998352dfdf7a6c70c6b602779c57c20 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 10 Nov 2023 14:32:17 +0000 Subject: [PATCH 06/11] Created fingertips_proxy as a global var --- R/zzz.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/zzz.R b/R/zzz.R index 4c0e85f..34d29c6 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,3 +1,5 @@ +utils::globalVariables("fingertips_proxy") + .onAttach <- function(libname, pkgname) { assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) From e60a56e7231fdd2e05ce9b603414d89a4a5521bb Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Thu, 16 Nov 2023 19:42:22 +0000 Subject: [PATCH 07/11] Updated to use function on function call rather than on pkg load. --- R/area_types.R | 12 ++++++------ R/deprivation_decile.R | 2 +- R/enhancements.R | 4 ++-- R/fingertips_data.R | 2 +- R/indicator_metadata.R | 4 ++-- R/indicators.R | 6 +++--- R/profiles.R | 2 +- R/retrieve_data.R | 2 +- R/utils.R | 29 ++++++++++++++++++++++++++-- R/zzz.R | 21 -------------------- man/area_types.Rd | 2 +- man/category_types.Rd | 2 +- man/deprivation_decile.Rd | 2 +- man/fingertips_data.Rd | 2 +- man/fingertips_proxy_settings.Rd | 14 ++++++++++++++ man/fingertips_stats.Rd | 2 +- man/get_fingertips_api.Rd | 2 +- man/indicator_areatypes.Rd | 2 +- man/indicator_metadata.Rd | 2 +- man/indicator_order.Rd | 2 +- man/indicator_update_information.Rd | 2 +- man/indicators.Rd | 2 +- man/indicators_unique.Rd | 2 +- man/nearest_neighbour_areatypeids.Rd | 2 +- man/nearest_neighbours.Rd | 2 +- man/profiles.Rd | 2 +- 26 files changed, 73 insertions(+), 55 deletions(-) delete mode 100644 R/zzz.R create mode 100644 man/fingertips_proxy_settings.Rd diff --git a/R/area_types.R b/R/area_types.R index 9d69681..4aa035e 100644 --- a/R/area_types.R +++ b/R/area_types.R @@ -43,7 +43,7 @@ #' Fingertips website within a Domain area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, ProfileID = NULL, - proxy_settings = fingertips_proxy, 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 +118,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 = fingertips_proxy, +category_types <- function(proxy_settings = fingertips_proxy_settings(), path) { if (missing(path)) path <- fingertips_endpoint() set_config(config(ssl_verifypeer = 0L)) @@ -165,7 +165,7 @@ category_types <- function(proxy_settings = fingertips_proxy, #' \code{\link{indicator_order}} for the order indicators are presented on the #' Fingertips website within a Domain indicator_areatypes <- function(IndicatorID, AreaTypeID, - proxy_settings = fingertips_proxy, path) { + proxy_settings = fingertips_proxy_settings(), path) { if (missing(path)) path <- fingertips_endpoint() fingertips_ensure_api_available( endpoint = path, @@ -224,7 +224,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 = fingertips_proxy, path) { + proxy_settings = fingertips_proxy_settings(), path) { if (missing(path)) path <- fingertips_endpoint() fingertips_ensure_api_available( @@ -292,7 +292,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID, measure, } areas_by_profile <- function(AreaTypeID, ProfileID, - proxy_settings = fingertips_proxy, path) { + proxy_settings = fingertips_proxy_settings(), path) { set_config(config(ssl_verifypeer = 0L)) fingertips_ensure_api_available( endpoint = path, @@ -346,7 +346,7 @@ areas_by_profile <- function(AreaTypeID, ProfileID, #' @examples #' \dontrun{ #' nearest_neighbour_areatypeids()} -nearest_neighbour_areatypeids <- function(proxy_settings = fingertips_proxy) { +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 471e197..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 = fingertips_proxy, 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 12d2812..fd23a1b 100644 --- a/R/enhancements.R +++ b/R/enhancements.R @@ -54,8 +54,8 @@ fingertips_redred <- function(Comparator = "England", ...) { #' # Returns a sentence describing number of indicators and profiles in Fingertips #' fingertips_stats()} #' @export -fingertips_stats <- function(proxy_settings = fingertips_proxy) { - fingertips_stats <- indicators(proxy_settings = proxy_settings) +fingertips_stats <- function(proxy_settings = fingertips_proxy_settings()) { + fingertips_stats <- indicators(proxy_settings = fingertips_proxy_settings()) summarised_stats <- fingertips_stats %>% summarise_if(is.integer, n_distinct) fingertips_stats <- sprintf("On %s Fingertips consisted of %s profiles, made up of %s indicators and %s distinct indicators.", diff --git a/R/fingertips_data.R b/R/fingertips_data.R index 38d9fd3..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 = fingertips_proxy, + 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 0bab8d1..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 = fingertips_proxy, + 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 = fingertips_proxy, 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 48623e4..16c4edd 100644 --- a/R/indicators.R +++ b/R/indicators.R @@ -31,7 +31,7 @@ indicators <- function(ProfileID = NULL, DomainID = NULL, - proxy_settings = fingertips_proxy, + 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 = fingertips_proxy, + 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 = fingertips_proxy, + 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 e03eea2..5398ed1 100644 --- a/R/profiles.R +++ b/R/profiles.R @@ -30,7 +30,7 @@ #' @export profiles <- function(ProfileID = NULL, ProfileName = NULL, - proxy_settings = fingertips_proxy, 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 18c5330..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 = fingertips_proxy) { + proxy_settings = fingertips_proxy_settings()) { proxy_settings <- match.arg( proxy_settings, diff --git a/R/utils.R b/R/utils.R index 4539889..56dc8ae 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 = fingertips_proxy) { + 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 = fingertips_proxy) { + proxy_settings = fingertips_proxy_settings()) { code <- FALSE endpoint <- gsub("/api/", "", endpoint) @@ -137,3 +137,28 @@ 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 +fingertips_proxy_settings <- function() { + + fingertips_proxy <- "default" + fingertips_proxy <- tryCatch( + { + fingertips_ensure_api_available(proxy_settings = "default") + }, error=function(e) {"none"} + ) + + if (fingertips_proxy == "none") { + tryCatch( + { + fingertips_ensure_api_available(proxy_settings = "none") + }, error=function(e) { + stop("The API is currently unavailable, you may need to reload fingertipsR when the API becomes available.") + } + ) +} + return(fingertips_proxy) +} diff --git a/R/zzz.R b/R/zzz.R deleted file mode 100644 index 34d29c6..0000000 --- a/R/zzz.R +++ /dev/null @@ -1,21 +0,0 @@ -utils::globalVariables("fingertips_proxy") - -.onAttach <- function(libname, pkgname) { - assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) - - tryCatch( - { - fingertips_ensure_api_available(proxy_settings = "default") - }, error=function(e) { - assign("fingertips_proxy", "none", envir=as.environment("package:fingertipsR")) - tryCatch( - { - fingertips_ensure_api_available(proxy_settings = "none") - }, error=function(e) { - assign("fingertips_proxy", "default", envir=as.environment("package:fingertipsR")) - packageStartupMessage("The API is currently unavailable, you may need to reload fingertipsR when the API becomes available.") - } - ) - } - ) -} diff --git a/man/area_types.Rd b/man/area_types.Rd index 6a9ba53..02adb5f 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 = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/category_types.Rd b/man/category_types.Rd index d3c644f..caad541 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -4,7 +4,7 @@ \alias{category_types} \title{Category types} \usage{ -category_types(proxy_settings = fingertips_proxy, path) +category_types(proxy_settings = fingertips_proxy_settings(), path) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/deprivation_decile.Rd b/man/deprivation_decile.Rd index ea072fb..18250e9 100644 --- a/man/deprivation_decile.Rd +++ b/man/deprivation_decile.Rd @@ -7,7 +7,7 @@ deprivation_decile( AreaTypeID, Year = 2019, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/fingertips_data.Rd b/man/fingertips_data.Rd index d49eece..d318d88 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 = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/fingertips_proxy_settings.Rd b/man/fingertips_proxy_settings.Rd new file mode 100644 index 0000000..d8a1d46 --- /dev/null +++ b/man/fingertips_proxy_settings.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{fingertips_proxy_settings} +\alias{fingertips_proxy_settings} +\title{fingertips_proxy_settings} +\usage{ +fingertips_proxy_settings() +} +\value{ +A character string with the proxy settings +} +\description{ +determines which proxy settings are used +} diff --git a/man/fingertips_stats.Rd b/man/fingertips_stats.Rd index e835165..1022857 100644 --- a/man/fingertips_stats.Rd +++ b/man/fingertips_stats.Rd @@ -4,7 +4,7 @@ \alias{fingertips_stats} \title{High level statistics on Fingertips data} \usage{ -fingertips_stats(proxy_settings = fingertips_proxy) +fingertips_stats(proxy_settings = fingertips_proxy_settings()) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/get_fingertips_api.Rd b/man/get_fingertips_api.Rd index 33bb39e..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 = fingertips_proxy + proxy_settings = fingertips_proxy_settings() ) } \arguments{ diff --git a/man/indicator_areatypes.Rd b/man/indicator_areatypes.Rd index 68118ef..5c06f93 100644 --- a/man/indicator_areatypes.Rd +++ b/man/indicator_areatypes.Rd @@ -7,7 +7,7 @@ indicator_areatypes( IndicatorID, AreaTypeID, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/indicator_metadata.Rd b/man/indicator_metadata.Rd index 37d0184..46d0975 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 = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/indicator_order.Rd b/man/indicator_order.Rd index 04e5582..9a8cbf9 100644 --- a/man/indicator_order.Rd +++ b/man/indicator_order.Rd @@ -8,7 +8,7 @@ indicator_order( DomainID, AreaTypeID, ParentAreaTypeID, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/indicator_update_information.Rd b/man/indicator_update_information.Rd index da5d0e6..d3eab2f 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 = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/indicators.Rd b/man/indicators.Rd index 4179b90..f0997d6 100644 --- a/man/indicators.Rd +++ b/man/indicators.Rd @@ -7,7 +7,7 @@ indicators( ProfileID = NULL, DomainID = NULL, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/indicators_unique.Rd b/man/indicators_unique.Rd index 3ce094d..f313e9a 100644 --- a/man/indicators_unique.Rd +++ b/man/indicators_unique.Rd @@ -7,7 +7,7 @@ indicators_unique( ProfileID = NULL, DomainID = NULL, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/nearest_neighbour_areatypeids.Rd b/man/nearest_neighbour_areatypeids.Rd index 5b3d0cf..d462587 100644 --- a/man/nearest_neighbour_areatypeids.Rd +++ b/man/nearest_neighbour_areatypeids.Rd @@ -4,7 +4,7 @@ \alias{nearest_neighbour_areatypeids} \title{Nearest neighbours area type ids} \usage{ -nearest_neighbour_areatypeids(proxy_settings = fingertips_proxy) +nearest_neighbour_areatypeids(proxy_settings = fingertips_proxy_settings()) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings diff --git a/man/nearest_neighbours.Rd b/man/nearest_neighbours.Rd index 19741c9..9ceb7eb 100644 --- a/man/nearest_neighbours.Rd +++ b/man/nearest_neighbours.Rd @@ -8,7 +8,7 @@ nearest_neighbours( AreaCode, AreaTypeID, measure, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } diff --git a/man/profiles.Rd b/man/profiles.Rd index ddf6cc2..3d364c9 100644 --- a/man/profiles.Rd +++ b/man/profiles.Rd @@ -7,7 +7,7 @@ profiles( ProfileID = NULL, ProfileName = NULL, - proxy_settings = fingertips_proxy, + proxy_settings = fingertips_proxy_settings(), path ) } From 40b44c34ba4055feeea2dbe9dd83b7c0e1fab52e Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 17 Nov 2023 09:36:55 +0000 Subject: [PATCH 08/11] Updated docs --- DESCRIPTION | 2 +- NEWS.md | 4 ++-- R/area_types.R | 2 +- R/utils.R | 1 + man/area_types.Rd | 2 +- man/category_types.Rd | 2 +- man/deprivation_decile.Rd | 2 +- man/fingertips_data.Rd | 2 +- man/fingertips_proxy_settings.Rd | 14 -------------- man/fingertips_stats.Rd | 2 +- man/indicator_areatypes.Rd | 2 +- man/indicator_metadata.Rd | 2 +- man/indicator_order.Rd | 2 +- man/indicator_update_information.Rd | 2 +- man/indicators.Rd | 2 +- man/indicators_unique.Rd | 2 +- man/nearest_neighbour_areatypeids.Rd | 2 +- man/nearest_neighbours.Rd | 2 +- man/profiles.Rd | 2 +- 19 files changed, 19 insertions(+), 32 deletions(-) delete mode 100644 man/fingertips_proxy_settings.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c8c0780..cdce93f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fingertipsR Type: Package -Version: 1.0.11.9001 +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 diff --git a/NEWS.md b/NEWS.md index e020904..7e3ab06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# fingertipsR 1.0.11.9001 (2023-10-11) +# fingertipsR 1.0.12 (2023-17-11) -* Determines if automatic proxy settings using internet explorer's settings should be used on package load. +* Automatically detects proxy settings in each function. # fingertipsR 1.0.11 (2023-09-11) diff --git a/R/area_types.R b/R/area_types.R index 4aa035e..2b85ebc 100644 --- a/R/area_types.R +++ b/R/area_types.R @@ -10,7 +10,7 @@ #' @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"; default determined automatically. #' @inheritParams indicators #' @examples #' \dontrun{ diff --git a/R/utils.R b/R/utils.R index 56dc8ae..4ba6f15 100644 --- a/R/utils.R +++ b/R/utils.R @@ -142,6 +142,7 @@ fingertips_deframe <- function(data) { #' fingertips_proxy_settings #' @description determines which proxy settings are used #' @return A character string with the proxy settings +#' @noRd fingertips_proxy_settings <- function() { fingertips_proxy <- "default" diff --git a/man/area_types.Rd b/man/area_types.Rd index 02adb5f..6c9e80b 100644 --- a/man/area_types.Rd +++ b/man/area_types.Rd @@ -22,7 +22,7 @@ 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"; 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 caad541..b77f8de 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -8,7 +8,7 @@ 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"; 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 18250e9..561cef2 100644 --- a/man/deprivation_decile.Rd +++ b/man/deprivation_decile.Rd @@ -20,7 +20,7 @@ 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"; 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 d318d88..157dc68 100644 --- a/man/fingertips_data.Rd +++ b/man/fingertips_data.Rd @@ -52,7 +52,7 @@ are returned also in AreaValuesCount} character vector} \item{proxy_settings}{string; whether to use Internet Explorer proxy settings -("default") or "none"} +"default" or "none"; default determined automatically.} \item{path}{String; Fingertips API address. Function will default to the correct address} diff --git a/man/fingertips_proxy_settings.Rd b/man/fingertips_proxy_settings.Rd deleted file mode 100644 index d8a1d46..0000000 --- a/man/fingertips_proxy_settings.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{fingertips_proxy_settings} -\alias{fingertips_proxy_settings} -\title{fingertips_proxy_settings} -\usage{ -fingertips_proxy_settings() -} -\value{ -A character string with the proxy settings -} -\description{ -determines which proxy settings are used -} diff --git a/man/fingertips_stats.Rd b/man/fingertips_stats.Rd index 1022857..3cff4ba 100644 --- a/man/fingertips_stats.Rd +++ b/man/fingertips_stats.Rd @@ -8,7 +8,7 @@ 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"; default determined automatically.} } \value{ A string that summarises the high level statistics of indicators and diff --git a/man/indicator_areatypes.Rd b/man/indicator_areatypes.Rd index 5c06f93..278e170 100644 --- a/man/indicator_areatypes.Rd +++ b/man/indicator_areatypes.Rd @@ -18,7 +18,7 @@ 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"; 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 46d0975..8d397ca 100644 --- a/man/indicator_metadata.Rd +++ b/man/indicator_metadata.Rd @@ -24,7 +24,7 @@ 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"; 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 9a8cbf9..3857bd9 100644 --- a/man/indicator_order.Rd +++ b/man/indicator_order.Rd @@ -24,7 +24,7 @@ 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"; 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 d3eab2f..f91d732 100644 --- a/man/indicator_update_information.Rd +++ b/man/indicator_update_information.Rd @@ -17,7 +17,7 @@ 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"; 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 f0997d6..c54f46b 100644 --- a/man/indicators.Rd +++ b/man/indicators.Rd @@ -17,7 +17,7 @@ indicators( \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"; 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 f313e9a..a0a072d 100644 --- a/man/indicators_unique.Rd +++ b/man/indicators_unique.Rd @@ -17,7 +17,7 @@ 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"; 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 d462587..ccea42a 100644 --- a/man/nearest_neighbour_areatypeids.Rd +++ b/man/nearest_neighbour_areatypeids.Rd @@ -8,7 +8,7 @@ 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"; default determined automatically.} } \value{ table of AreaTypeIDs diff --git a/man/nearest_neighbours.Rd b/man/nearest_neighbours.Rd index 9ceb7eb..9ca06ab 100644 --- a/man/nearest_neighbours.Rd +++ b/man/nearest_neighbours.Rd @@ -23,7 +23,7 @@ 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"; 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 3d364c9..75bbfe2 100644 --- a/man/profiles.Rd +++ b/man/profiles.Rd @@ -17,7 +17,7 @@ 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"; default determined automatically.} \item{path}{String; Fingertips API address. Function will default to the correct address} From d223207f56b073270a2600fbefef308f99718aba Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 17 Nov 2023 10:12:34 +0000 Subject: [PATCH 09/11] Updated docs, fixed error if API is unavailable. --- R/area_types.R | 3 ++- R/utils.R | 9 +++++---- man/area_types.Rd | 3 ++- man/category_types.Rd | 3 ++- man/deprivation_decile.Rd | 3 ++- man/fingertips_data.Rd | 3 ++- man/fingertips_stats.Rd | 3 ++- man/indicator_areatypes.Rd | 3 ++- man/indicator_metadata.Rd | 3 ++- man/indicator_order.Rd | 3 ++- man/indicator_update_information.Rd | 3 ++- man/indicators.Rd | 3 ++- man/indicators_unique.Rd | 3 ++- man/nearest_neighbour_areatypeids.Rd | 3 ++- man/nearest_neighbours.Rd | 3 ++- man/profiles.Rd | 3 ++- 16 files changed, 35 insertions(+), 19 deletions(-) diff --git a/R/area_types.R b/R/area_types.R index 2b85ebc..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 determined automatically. +#' "default" or "none". Setting this manually will decrease runtime; +#' default determined automatically. #' @inheritParams indicators #' @examples #' \dontrun{ diff --git a/R/utils.R b/R/utils.R index 4ba6f15..e05bd49 100644 --- a/R/utils.R +++ b/R/utils.R @@ -153,13 +153,14 @@ fingertips_proxy_settings <- function() { ) if (fingertips_proxy == "none") { - tryCatch( + errtext <- tryCatch( { fingertips_ensure_api_available(proxy_settings = "none") - }, error=function(e) { - stop("The API is currently unavailable, you may need to reload fingertipsR when the API becomes available.") - } + }, error=function(e) {"The API is currently unavailable."} ) + 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 6c9e80b..4041572 100644 --- a/man/area_types.Rd +++ b/man/area_types.Rd @@ -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 determined automatically.} +"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 b77f8de..4835e07 100644 --- a/man/category_types.Rd +++ b/man/category_types.Rd @@ -8,7 +8,8 @@ category_types(proxy_settings = fingertips_proxy_settings(), path) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings -"default" or "none"; default determined automatically.} +"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 561cef2..ba83924 100644 --- a/man/deprivation_decile.Rd +++ b/man/deprivation_decile.Rd @@ -20,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 determined automatically.} +"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 157dc68..898da14 100644 --- a/man/fingertips_data.Rd +++ b/man/fingertips_data.Rd @@ -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 determined automatically.} +"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 3cff4ba..785bf8e 100644 --- a/man/fingertips_stats.Rd +++ b/man/fingertips_stats.Rd @@ -8,7 +8,8 @@ fingertips_stats(proxy_settings = fingertips_proxy_settings()) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings -"default" or "none"; default determined automatically.} +"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/indicator_areatypes.Rd b/man/indicator_areatypes.Rd index 278e170..7d03903 100644 --- a/man/indicator_areatypes.Rd +++ b/man/indicator_areatypes.Rd @@ -18,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 determined automatically.} +"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 8d397ca..f1e9e7c 100644 --- a/man/indicator_metadata.Rd +++ b/man/indicator_metadata.Rd @@ -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 determined automatically.} +"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 3857bd9..da59054 100644 --- a/man/indicator_order.Rd +++ b/man/indicator_order.Rd @@ -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 determined automatically.} +"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 f91d732..57e92fa 100644 --- a/man/indicator_update_information.Rd +++ b/man/indicator_update_information.Rd @@ -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 determined automatically.} +"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 c54f46b..e66b70c 100644 --- a/man/indicators.Rd +++ b/man/indicators.Rd @@ -17,7 +17,8 @@ indicators( \item{DomainID}{Numeric vector, id of domains of interest} \item{proxy_settings}{string; whether to use Internet Explorer proxy settings -"default" or "none"; default determined automatically.} +"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 a0a072d..76b62a5 100644 --- a/man/indicators_unique.Rd +++ b/man/indicators_unique.Rd @@ -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 determined automatically.} +"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 ccea42a..82ff84b 100644 --- a/man/nearest_neighbour_areatypeids.Rd +++ b/man/nearest_neighbour_areatypeids.Rd @@ -8,7 +8,8 @@ nearest_neighbour_areatypeids(proxy_settings = fingertips_proxy_settings()) } \arguments{ \item{proxy_settings}{string; whether to use Internet Explorer proxy settings -"default" or "none"; default determined automatically.} +"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 9ca06ab..b41dd18 100644 --- a/man/nearest_neighbours.Rd +++ b/man/nearest_neighbours.Rd @@ -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 determined automatically.} +"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 75bbfe2..16c5376 100644 --- a/man/profiles.Rd +++ b/man/profiles.Rd @@ -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 determined automatically.} +"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} From 47bb1aba9985f88bbf59988c1123f58571f576e7 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 17 Nov 2023 10:45:20 +0000 Subject: [PATCH 10/11] Stopped overwriting proxy_settings when using "default" --- R/utils.R | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/R/utils.R b/R/utils.R index e05bd49..28aab71 100644 --- a/R/utils.R +++ b/R/utils.R @@ -145,22 +145,27 @@ fingertips_deframe <- function(data) { #' @noRd fingertips_proxy_settings <- function() { + # First try using default as proxy settings fingertips_proxy <- "default" - fingertips_proxy <- tryCatch( + errtext <- tryCatch( { fingertips_ensure_api_available(proxy_settings = "default") - }, error=function(e) {"none"} + }, error=function(e) {"The API is currently unavailable."} ) - if (fingertips_proxy == "none") { + # 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."} - ) + { + 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) } From 901aa66a3c612d9832b7377d9ad5ec020d7f2412 Mon Sep 17 00:00:00 2001 From: Nanayakkara Date: Fri, 17 Nov 2023 10:58:27 +0000 Subject: [PATCH 11/11] Parsed proxy_settings --- R/enhancements.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/enhancements.R b/R/enhancements.R index fd23a1b..6bb18e3 100644 --- a/R/enhancements.R +++ b/R/enhancements.R @@ -55,7 +55,7 @@ fingertips_redred <- function(Comparator = "England", ...) { #' fingertips_stats()} #' @export fingertips_stats <- function(proxy_settings = fingertips_proxy_settings()) { - fingertips_stats <- indicators(proxy_settings = fingertips_proxy_settings()) + fingertips_stats <- indicators(proxy_settings = proxy_settings) summarised_stats <- fingertips_stats %>% summarise_if(is.integer, n_distinct) fingertips_stats <- sprintf("On %s Fingertips consisted of %s profiles, made up of %s indicators and %s distinct indicators.",