title | author | date | output |
---|---|---|---|
Compare Versions |
Philipp Ottolinger |
8 April 2016 |
html_document |
get_github_version <- function(url) {
repo <- gsub("https://github.com/", url, replacement = "")
raw_description_str <- paste("https://raw.githubusercontent.com/", repo, "/master/DESCRIPTION", sep = "")
raw_description <- getURL(raw_description_str)
# better use some regex here!
version <- sapply(strsplit(raw_description, "Version: "), "[", 2)
version <- sapply(strsplit(version, "\n"), "[", 1)
return(version)
}
url <- "https://github.com/daattali/shinyjs"
get_github_version(url)
## [1] "0.5.3"
get_cran_version <- function(package) {
url <- paste("https://cran.r-project.org/web/packages/", package, "/", sep = "")
file <- getURL(url)
# better use some regex here!
version <- sapply(strsplit(file, "Version:</td>\n<td>"), "[", 2)
version <- sapply(strsplit(version, "<"), "[", 1)
return(version)
}
package <- "shinyjs"
get_cran_version(package)
## [1] "0.5.2"
compare_versions <- function(CRAN, GitHub) {
table <- data.frame("CRAN" = get_cran_version(CRAN),
"GitHub" = get_github_version(GitHub))
rownames(table) <- "Version"
return(table)
}
compare_versions(CRAN = package, GitHub = url)
## CRAN GitHub
## Version 0.5.2 0.5.3