Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limited curl::has_internet() to areas where strictly necessary #155

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
limited curl::has_internet() to areas where strictly necessary
so that function can also use download.file()
  • Loading branch information
Bates, Colm authored and Bates, Colm committed Jan 20, 2020
commit 5e2e1e81aefbec11bd567d03e62b06c2d81b3022
5 changes: 1 addition & 4 deletions R/get_eurostat.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ get_eurostat <- function(id, time_format = "date", filters = "none",
stringsAsFactors = default.stringsAsFactors(),
keepFlags = FALSE, ...){

# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")


#Warning for flags with filter
if (keepFlags & !is.character(filters) && filters != "none") {
warning("The keepFlags argument of the get_eurostat function can be used only without filters.
Expand Down
24 changes: 24 additions & 0 deletions R/get_eurostat_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@ get_eurostat_raw <- function(id) {

dat
}



#' @title Check if download.file() can access the internet
#' @description Check if download.file() can access the internet.
#' @return A Boolean which corresponds to if base function download.file() can access the internet
#' @author Colm Bates
#' @examples
#' \dontrun{
#' eurostat:::has_internet:::download.file()
#'
#' }

has_internet_download.file <- function(){
temp <- tempfile()
suppressWarnings(try(download.file("http://captive.apple.com/html", temp, quiet= TRUE), silent = TRUE))
if (is.na(file.info(temp)$size)){
FALSE
}
else{
data<- readChar(temp, file.info(temp)$size)
grepl("Success", readChar(temp, file.info(temp)$size), data)
}
}