R/inepdata.R

#####
## Auxiliary functions
###

# Prints verbose information
#
# @param ...
#
# @examples
Verbose_ <- function(...) if (.options$verbose) cat(..., sep = "")
Verbose  <- function(...) Verbose_(..., "\n")

# Evaluates if an URL exists
#
# @param url URL to be verified
#
# @return logical
#
check.url.function <- RCurl::url.exists
        # defining this basic function in only one place for quick replacement if needed
is.url.valid <- function(url){
    valid <- ifelse(.options$offline, TRUE, check.url.function(url))
    Verbose("is.url.valid == ", valid)
    return(valid)
}

# Verifies internet connection state
#
# @return logical
#
is.internet.ok <- function() {
    ok <- is.url.valid("https://www.google.com/") # if google is down, then the world has ended XD
    Verbose("is.internet.ok == ", ok)
    return(ok)
}

# Checks whether internet is up or down
#
check.internet <- function() {
    if (!is.internet.ok())
        stop("Will need to download files, ",
             "but no internet connection has been found.",
             "\n\n",
             "Try again when connection established.")
}

# String concatenation written short
#
`%+%` <- function(a, b) {
    return(stringr::str_c(a, b))
}
zyxdef/inepdata documentation built on May 8, 2019, 11:59 p.m.