R/is_link_broken.R

Defines functions is_link_broken

Documented in is_link_broken

#' Determines if a link is valid
#'
#' Used in testing links to external data, specifically inside of internal
#' package tests. Attempts to connect to link for the length of duration (in s).
#' If it fails it returns \code{TRUE}
#'
#' @param link_to_test a link
#' @param duration the lowest row number
#' @return \code{FALSE} if the link works, \code{TRUE} if it fails
#'
#' @export


is_link_broken <- function(link_to_test, duration = 1) {
  link_to_test <- url(link_to_test)
  result <-
    suppressWarnings(try(open.connection(link_to_test, open = "rt", timeout = duration),
                         silent =
                           TRUE)
                     [1])

  suppressWarnings(try(close.connection(link_to_test), silent = TRUE)
  )
  ifelse(is.null(result), FALSE, TRUE)

}

Try the JumpeR package in your browser

Any scripts or data that you put into this service are public.

JumpeR documentation built on Nov. 17, 2021, 1:07 a.m.