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

check_url(url, timeout = 2L)

Source

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

Arguments

url

Character. The URL to be checked.

timeout

Numeric. 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

load_packages(purrr, tibble)

urls <- c(
     "http://www.amazon.com", "http://this.isafakelink.biz",
     "https://stackoverflow.com", "https://stackoverflow505.com")
purrr::map_dfr(urls, ~tibble::tibble(URL = .x, Valid = check_url(.x)))
#> # A tibble: 4 × 2
#>   URL                          Valid
#>   <chr>                        <lgl>
#> 1 http://www.amazon.com        TRUE 
#> 2 http://this.isafakelink.biz  FALSE
#> 3 https://stackoverflow.com    TRUE 
#> 4 https://stackoverflow505.com FALSE