Created
May 20, 2016 13:40
-
-
Save ottlngr/3d4c15844e18f8e8ef71f8e4f10e9452 to your computer and use it in GitHub Desktop.
Case study: Compare package versions on CRAN and GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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