How to determine if you have an internet connection in R -
sometimes need download data internet. on occasions has failed either because website down or because computer has lost internet connection.
question: there function in r return true/false whether connected internet?
here attempt @ parsing output ipconfig/ifconfig, suggested spacedman.
havingip <- function() { if (.platform$os.type == "windows") { ipmessage <- system("ipconfig", intern = true) } else { ipmessage <- system("ifconfig", intern = true) } validip <- "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.]){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" any(grep(validip, ipmessage)) } with simple true/false output
> havingip() [1] true
Comments
Post a Comment