R/utils.R

Defines functions urlExists

Documented in urlExists

#' Pipe operator
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @export
NULL

#' Compound_pipe
#'
#' @name %<>%
#' @rdname compound_pipe
#' @keywords internal
#' @importFrom magrittr %<>%
#' @usage lhs \%<>\% rhs
#' @export
NULL


#' @title urlExists
#' @description A utility function to run a tryCatch on a URL.
#' @param target url
#' @export
urlExists <- function(target) {
    tryCatch({
        con <- url(target)
        a  <- capture.output(suppressWarnings(readLines(con)))
        close(con)
        TRUE;
    },
    error = function(err) {
        occur <- grep("cannot open the connection", capture.output(err));
        if(length(occur) > 0) FALSE;
    }
    )
}

Try the baseballDBR package in your browser

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

baseballDBR documentation built on May 2, 2019, 5:56 a.m.