Sometimes I need to download data from the internet. On occasions this has failed either because the website is down or because my computer has lost its internet connection.
All these answers use packages or code outside of base R. Here's how to do it with just base R:
# IANA's test website is_online <- function(site="http://example.com/") { tryCatch({ readLines(site,n=1) TRUE }, warning = function(w) invokeRestart("muffleWarning"), error = function(e) FALSE) }