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.
Just another one to add to the pot, inspired by @romans answer, this works only on Windows I'd assume, not sure about other platforms:
canPingSite <- function(test.site) {
!as.logical(system(paste("ping", test.site)))
}
Which we test as follows:
> t1 <- canPingSite("www.yahoo.com")
[...]
> t2 <- canPingSite(";lkjsdflakjdlfhasdfhsad;fs;adjfsdlk")
[...]
> t1; t2
[1] TRUE
[1] FALSE