R/isConnected.R

Defines functions .isConnected

## borrowed from our dang package, but made internal here, in order to not have
## to declare a dependency for just these few lines of code
##
## Copyright Dirk Eddelbuettel
## Licensed as GPL (>= 2)
## https://cran.r-project.org/package=dang

.isConnected <- function(site="https://www.google.com") {
    uoc <- function(site) {
        con <- url(site)                # need to assign so that we can close
        open(con)                       # in case of success we have a connection
        close(con)                      # ... so we need to clean up
    }
    suppressWarnings(!inherits(try(uoc(site), silent=TRUE), "try-error"))
}

Try the tint package in your browser

Any scripts or data that you put into this service are public.

tint documentation built on Nov. 2, 2022, 1:06 a.m.