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.
Question: Is there some function in R which will return TRUE/FALSE as to whether I am connected to the internet?
Enter the necessary information on the Connect to R‑Studio dialog box and click the Connect button. Specify the DNS name or IP address of the host where R‑Studio is running. Specify the port set on the R‑Studio Connect to Remote Computer dialog box.
R clients using RStudio Package Manager do not need internet access, just access to RStudio Package Manager. RStudio Package Manager is designed to help organizations with restricted internet access in their R environment.
Senior Member. That R, and the description on your homescreen, mean that you are in Roaming mode; you are not in your own carrier's network.
The curl
package has a function has_internet
which tests by performing a nslookup
:
curl::has_internet ## function(){ ## !is.null(nslookup("google.com", error = FALSE)) ## }
Testing DNS is faster and may be more reliable than retrieving a URL because the latter might fail for unrelated reasons (e.g. firewall, server down, etc).
A dirty work around would be using RCurl::getURL
function.
if (is.character(getURL("www.google.com"))) { out <- TRUE } else { out <- FALSE }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With