diff --git a/DESCRIPTION b/DESCRIPTION index 35c66989..1506e1bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: pxweb Title: R Interface to PXWEB APIs -Version: 0.16.3 -Date: 2024-01-13 +Version: 0.17.0 +Date: 2024-01-28 Authors@R: c( person("Mans", "Magnusson", , "mons.magnusson@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-0296-2719")), @@ -35,6 +35,7 @@ Depends: R (>= 3.5.0) Imports: checkmate, + curl, httr (>= 1.1), jsonlite Suggests: diff --git a/R/pxweb.R b/R/pxweb.R index 8c9e19d0..04d42325 100644 --- a/R/pxweb.R +++ b/R/pxweb.R @@ -29,6 +29,10 @@ #' #' @export pxweb <- function(url) { + if(!curl::has_internet()){ + message(no_internet_msg()) + return(NULL) + } if (is.pxweb(url)) { return(url) } @@ -119,3 +123,7 @@ pxweb_tempdir <- function(to = "apis") { return(tmp_dir_logs) } } + +no_internet_msg <- function(){ + return("No internet access.") +} diff --git a/R/pxweb_get.R b/R/pxweb_get.R index 037017be..558f4689 100644 --- a/R/pxweb_get.R +++ b/R/pxweb_get.R @@ -95,6 +95,10 @@ pxweb_get_data <- function(url, query, verbose = TRUE, column.name.type = "text" #' both \code{httr::POST} and \code{httr::GET}. #' @export pxweb_advanced_get <- function(url, query = NULL, verbose = TRUE, log_http_calls = FALSE, pxmdo = NULL, ...) { + if(!curl::has_internet()){ + message(no_internet_msg()) + return(NULL) + } checkmate::assert_flag(log_http_calls) checkmate::assert_class(pxmdo, classes = "pxweb_metadata", null.ok = TRUE) if (log_http_calls) { diff --git a/R/pxweb_interactive.R b/R/pxweb_interactive.R index 1dc413e8..fa6bb279 100644 --- a/R/pxweb_interactive.R +++ b/R/pxweb_interactive.R @@ -23,6 +23,10 @@ #' ## x <- pxweb_interactive(x = "https://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0101/BE0101A/") #' pxweb_interactive <- function(x = NULL) { + if(!curl::has_internet()){ + message(no_internet_msg()) + return(NULL) + } # Setup structure pxe <- pxweb_explorer(x)