Skip to content

Instantly share code, notes, and snippets.

@leeper
Last active January 9, 2016 20:37
Show Gist options
  • Save leeper/d1c655746c72a5b585d1 to your computer and use it in GitHub Desktop.
Save leeper/d1c655746c72a5b585d1 to your computer and use it in GitHub Desktop.
CRAN Package Age
library("httr")
library("XML")
x <- content(httr::GET("https://cran.r-project.org/web/packages/available_packages_by_date.html"), as = "text")
p <- readHTMLTable(x, stringsAsFactors = FALSE)[[1]]
names(p) <- trimws(names(p))
p$Days <- Sys.Date() - as.Date(p$Date)
h <- hist(-as.numeric(p$Days), breaks = seq(from = -(365*11), to = 0, by = 365/4), plot = FALSE)
barplot(h$counts, space = 0, las = 1,
col = rainbow(length(h$counts)),
main = sprintf("Age of CRAN Packages (as of %s)", Sys.Date()),
xlab = "Years Since Last Update", xaxt = "n", xaxs = "i",
ylab = "", yaxs = "i")
axis(1, seq(from = 0, to = 44, by = 4), seq(-11, 0, by = 1))
# median package age
m <- median(as.numeric(p$Days))
m2 <- length(h$counts) - 4*m/365
abline(v = m2, lwd = 3)
text(x = m2, y = max(h$counts) - 100, sprintf("Median Age: %d Days", m), pos = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment