Skip to content

Instantly share code, notes, and snippets.

@ottlngr
Created May 20, 2016 13:40
Show Gist options
  • Save ottlngr/3d4c15844e18f8e8ef71f8e4f10e9452 to your computer and use it in GitHub Desktop.
Save ottlngr/3d4c15844e18f8e8ef71f8e4f10e9452 to your computer and use it in GitHub Desktop.
Case study: Compare package versions on CRAN and GitHub
library(RCurl)
library(magrittr)
library(stringr)
compare_versions <- function(package) {
cranurl <- paste("https://cran.r-project.org/web/packages/", package, "/", sep = "")
cranfile <- getURL(cranurl)
cranversion <- cranfile %>%
str_extract("(?<=Version:</td>\n<td>)[0-9a-zA-Z.-]*")
ghurl <- cranfile %>%
str_extract('(?<=URL:</td>\n<td>).*') %>%
str_extract("(?<=>).*") %>%
str_extract('(.*?)(?=<)')
ghversion <- ghurl %>%
str_extract("(?<=.com/).*") %>%
paste("https://raw.githubusercontent.com/", . , "/master/DESCRIPTION", sep = "") %>%
getURL() %>%
str_extract("(?<=Version: ).*")
table <- data.frame(cranversion, ghversion, stringsAsFactors = F) %>%
`colnames<-`(c("CRAN Version", "GitHub Version"))
return(table)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment