Skip to content

Instantly share code, notes, and snippets.

Last active Jun 18, 2019
What would you like to do?
Check CRAN Results
# started with `foghorn`, but that comes with dependencies and
# slows down R startup. `browseURL` just barely slows startup,
# even if actual page is slow to load.
check_cran_old <- function(email) {
gsub("[^A-Za-z0-9_:.-]", "_", sub("@", "_at_", email))
) ) }
if(interactive()) check_cran_old("")
# an alternative that is not as disruptive as `browserURL`.
# The regex is likely to be pretty fragile to changes in
# page structure, but the benefit is no dependencies:
check_cran <- function(
email, cache='~/.R-cran-status.RDS', * 3600
) {
url <- sprintf(
gsub("[^A-Za-z0-9_:.-]", "_", sub("@", "_at_", email))
display_check <- function(x, extra=NULL) {
err.cols <- unlist(x[names(x) %in% c("WARNING", "ERROR")])
if(sum(as.numeric(err.cols), na.rm=TRUE))
writeLines(c("\033[41mErrors/Warnings Present\033[m", url))
writeLines(c(extra, ""))
renew.cache <- TRUE
if(file.exists(cache)) {
cache.dat <- readRDS(cache)
cache.age <- Sys.time() - cache.dat[[1]]
if(as.double(cache.age, 'secs') < {
renew.cache <- FALSE
"cached CRAN status (%s old).", format(round(cache.age))
) ) ) } }
if(renew.cache) {
cat("connecting to CRAN...")
page <- readLines(url)
cat("\r \r")
pattern <- "\\s*<t[hd].*?>(.*?)</t[hd]>"
has.rows <- grep(pattern, page, perl=TRUE)
strings <- gregexpr(pattern, page[has.rows], perl=TRUE)
res <- sapply(
regmatches(page[has.rows], strings),
function(x) {
submatch <- regexec(pattern, x, perl=TRUE)
vapply(regmatches(x, submatch), "[[", character(1L), 2)
) <- t(gsub("<[^>]*>|^\\s+|\\s+$", "", res)) <-[-1, ]
colnames( <-[1, ]
res.df <-, stringsAsFactors=FALSE)
saveRDS(list(Sys.time(), res.df), cache)
if(interactive()) check_cran('')
Copy link

adamhsparks commented Aug 29, 2018

Line 65: if(interactive) check_cran('')

should be

if(interactive()) check_cran('')

Copy link

adamhsparks commented Aug 29, 2018

It works, reporting the values as your screenshot on Twitter did, but I get this error on start.

Error in display_check(cache.dat[[2]], c("", sprintf("cached CRAN status (%s old).", : (list) object cannot be coerced to type 'double'

Copy link

brodieG commented Aug 29, 2018

You must have Errors/Warnings on CRAN! I did not have them when I wrote this, so that branch of the code was not properly tested. I just fixed it. Let me know if it still doesn't work for you. (@adamhsparks; not sure how notifications work on gist).

Thanks for helping test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment