boB Rudis
5 years ago
9 changed files with 147 additions and 93 deletions
@ -0,0 +1,44 @@ |
|||
#' Check package URLs |
|||
#' |
|||
#' @param just_pass_or_fail if `TRUE` (default is `FALSE`) just return `TRUE` if |
|||
#' all the URL checks result in HTTP `200` status codes. |
|||
#' @export |
|||
check_package_urls <- function(just_pass_or_fail = FALSE) { |
|||
|
|||
m_GET <- memoise::memoise(httr::GET) # avoid checking URL more than once |
|||
|
|||
tc <- function(x, where = NULL) { |
|||
if (length(where)) message("- Looking in ", where, " files...") |
|||
tryCatch(x, error = function(e) NULL) |
|||
} |
|||
|
|||
pkg <- tc(rprojroot::find_package_root_file()) |
|||
|
|||
if (is.null(pkg)) stop("Could not find package root.", call.=FALSE) |
|||
|
|||
message("Gathering URLs for {", basename(pkg), "} (this may take a bit)") |
|||
|
|||
dplyr::bind_rows( |
|||
tc(tools:::url_db_from_package_HTML_files(pkg), "HTML"), |
|||
tc(tools:::url_db_from_package_metadata(pkg), "metadata"), |
|||
tc(tools:::url_db_from_package_news(pkg), "news"), |
|||
tc(tools:::url_db_from_package_NEWS_md(pkg)), |
|||
tc(tools:::url_db_from_package_Rd_db(pkg), "Rd"), |
|||
tc(tools:::url_db_from_package_README_md(pkg), "README"), |
|||
tc(tools:::url_db_from_package_sources(pkg), "source"), |
|||
tc(tools:::url_db_from_PDF_files(pkg), "PDF"), |
|||
) %>% |
|||
dplyr::distinct() %>% |
|||
{ .pb <<- dplyr::progress_estimated(nrow(.)) ; |
|||
message("\nChecking found URLs (this may also take a bit)") |
|||
. } %>% |
|||
dplyr::mutate(status = purrr::map_dbl(URL, ~{ |
|||
.pb$tick()$print() |
|||
tryCatch(httr::status_code(m_GET(url = .x)), error = 599) |
|||
})) %>% |
|||
janitor::clean_names() %>% |
|||
tibble::as_tibble() -> out |
|||
|
|||
if (just_pass_or_fail) all(out$status == 200) else print(out, nrow(out)) |
|||
|
|||
} |
@ -0,0 +1,15 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/check-package-urls.R |
|||
\name{check_package_urls} |
|||
\alias{check_package_urls} |
|||
\title{Check package URLs} |
|||
\usage{ |
|||
check_package_urls(just_pass_or_fail = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{just_pass_or_fail}{if `TRUE` (default is `FALSE`) just return `TRUE` if |
|||
all the URL checks result in HTTP `200` status codes.} |
|||
} |
|||
\description{ |
|||
Check package URLs |
|||
} |
Before Width: | Height: | Size: 136 KiB |
Loading…
Reference in new issue