Skip to contents

This function opens a connection to the specified URL to check its validity. It returns TRUE if the URL is valid (i.e., the connection can be opened), and FALSE otherwise.

Usage

CheckURL(url_in, t = 2)

Source

The source code of this function was taken from this stackoverflow discussion.

Arguments

url_in

A character string specifying the URL to be checked.

t

A numeric value specifying the timeout in seconds for the connection attempt. Default is 2 seconds.

Value

A logical value: TRUE if the URL is valid, FALSE if not.

Examples

urls <- c(
     "http://www.amazon.com", "http://this.isafakelink.biz",
     "https://stackoverflow.com", "https://stack-overflow.com")
sapply(urls, CheckURL)
#>       http://www.amazon.com http://this.isafakelink.biz 
#>                        TRUE                       FALSE 
#>   https://stackoverflow.com  https://stack-overflow.com 
#>                        TRUE                        TRUE