A function to test if I get a response from a URL
Details
gratefully pilfered from https://stackoverflow.com/questions/52911812/check-if-url-exists-in-r
See also
Other helper:
load_catalog_csv_as_DT()
,
marco()
,
print_error_block()
,
print_warning_block()
,
util_unzip()
Examples
#EXAMPLE1
some_urls <-
c(
"https://jimcoll.github.io/a/bad/programmer/", # Should 404
"https://github.com/NOAA-OWP/inundation-mapping", # Should exist
"https://nooneshouldeverhavethisurl.gov/badtest" # Does not exist in any form
)
data.frame(
exists = sapply(some_urls, url_exists, USE.NAMES = FALSE),
some_urls,
stringsAsFactors = FALSE
) %>% tibble::as_tibble() %>% print()
#> Warning: Requests for [https://jimcoll.github.io/a/bad/programmer/] responded but without an HTTP status code in the 200-299 range
#> # A tibble: 3 × 2
#> exists some_urls
#> <lgl> <chr>
#> 1 FALSE https://jimcoll.github.io/a/bad/programmer/
#> 2 TRUE https://github.com/NOAA-OWP/inundation-mapping
#> 3 NA https://nooneshouldeverhavethisurl.gov/badtest