-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support all version, R-release, R-oldrel separately
Remove magrittr dependency, add XML dependency.
- Loading branch information
1 parent
e39c19f
commit 4783625
Showing
9 changed files
with
915 additions
and
93 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Generated by roxygen2 (4.0.2): do not edit by hand | ||
|
||
export(r_oldrel) | ||
export(r_release) | ||
export(r_versions) | ||
importFrom(RCurl,getURLContent) | ||
importFrom(magrittr,"%>%") | ||
importFrom(XML,xmlChildren) | ||
importFrom(XML,xmlParse) | ||
importFrom(XML,xmlRoot) | ||
importFrom(XML,xmlValue) | ||
importFrom(XML,xpathApply) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,99 @@ | ||
|
||
#' Query which versions R-release and R-oldrel refer to | ||
#' Query R's past and present versions | ||
#' | ||
#' R version numbers consist of three numbers (since version 1.4.1): | ||
#' major, minor and patch. | ||
#' | ||
#' We use the latest (in terms of versions numbers) tag in the | ||
#' R SVN repository to determine R-release. | ||
#' | ||
#' For R-oldrel, the latest version of the previous minor version | ||
#' is used, again, based on the SVN repo. | ||
#' We extract the version numbers from the tags in the SVN repository. | ||
#' | ||
#' @return A named character vector with entries \code{release} and | ||
#' \code{oldrel}. | ||
#' @param dots Whether to use dots instead of dashes in the version | ||
#' number. | ||
#' @return A list, where each entry is an R version and has two | ||
#' entries: \sQuote{version} is the version number itself, | ||
#' \sQuote{date} is the exact date and time when this R version was | ||
#' released. | ||
#' | ||
#' @export | ||
#' @importFrom RCurl getURLContent | ||
#' @importFrom magrittr %>% | ||
#' @importFrom XML xmlParse xmlRoot xmlChildren xpathApply xmlValue | ||
#' @examples | ||
#' r_versions() | ||
|
||
r_versions <- function() { | ||
|
||
## Get the tag info from SVN | ||
tags <- getURLContent( | ||
"http://svn.r-project.org/R/tags/", | ||
customrequest = "PROPFIND", | ||
httpheader=c("Depth"="1") | ||
) %>% | ||
get_tags() | ||
|
||
## Extract versions numbers from tags and sort them | ||
versions <- tags %>% | ||
sub(pattern = "/R/tags/R-([^/]+)/", replacement = "\\1") %>% | ||
grep(pattern = "^[0-9]+-[0-9]+(-[0-9]+|)$", value = TRUE) %>% | ||
sort_tags() | ||
|
||
## Relase is easy, most recent | ||
release <- tail(versions, 1) | ||
|
||
## Oldrel is latest from the previous minor | ||
## (Careful with factors, they are ordered by default!) | ||
oldrel <- versions %>% | ||
sub(pattern = "-[0-9]+$", replacement = "") %>% | ||
factor(levels = unique(.)) %>% | ||
tapply(X = versions, FUN = tail, 1) %>% | ||
tail(2) %>% | ||
head(1) %>% | ||
unname() | ||
|
||
c(release = release, oldrel = oldrel) %>% | ||
gsub(pattern = "-", replacement = ".") | ||
} | ||
r_versions <- function(dots = TRUE) { | ||
|
||
props<- getURLContent("http://svn.r-project.org/R/tags/", | ||
customrequest = "PROPFIND", | ||
httpheader=c("Depth"="1") ) | ||
props <- xmlParse(props) | ||
props <- xmlRoot(props) | ||
props <- xmlChildren(props) | ||
props <- lapply(props, get_props) | ||
props <- unname(props) | ||
|
||
tags <- sapply(props, get_tags) | ||
tags <- sub("^.*/tags/R-([-0-9]+).*$", "\\1", tags) | ||
|
||
dates <- sapply(props, get_dates) | ||
|
||
get_tags <- function(xml) { | ||
xml2 <- xml %>% | ||
gsub(pattern = "<D:propstat>(.*?)</D:propstat>", replacement = "") | ||
versions <- grepl("^[0-9]+-[0-9]+(-[0-9]+|)$", tags) | ||
tags <- tags[versions] | ||
dates <- dates[versions] | ||
|
||
matches <- xml2 %>% | ||
gregexpr(pattern = "<D:href>[^<]+</D:href>") | ||
if (dots) tags <- gsub('-', '.', tags) | ||
|
||
regmatches(xml2, matches)[[1]] %>% | ||
sub(pattern = "<D:href>", replacement = "") %>% | ||
sub(pattern = "</D:href>", replacement = "") | ||
versions <- mapply(FUN = list, version = tags, date = dates, | ||
SIMPLIFY = FALSE) | ||
versions <- versions[order(package_version(tags))] | ||
|
||
versions | ||
} | ||
|
||
## Split a version number to major, minor, patch | ||
split_versions <- function(x) { | ||
x %>% | ||
sub(pattern = "^([0-9]+-[0-9]+)$", replacement = "\\1-0") %>% | ||
strsplit(split = "-") %>% | ||
sapply(as.numeric) | ||
|
||
#' Version number of R-release | ||
#' | ||
#' The latest tag in the SVN repository (in terms of version numbers, | ||
#' not dates). | ||
#' | ||
#' @inheritParams r_versions | ||
#' | ||
#' @export | ||
#' @examples | ||
#' r_release() | ||
|
||
r_release <- function(dots = TRUE) { | ||
tail(r_versions(dots), 1)[[1]] | ||
} | ||
|
||
## Sort version numbers | ||
sort_tags <- function(x) { | ||
x_order <- x %>% | ||
split_versions() %>% | ||
apply(1, list) %>% | ||
lapply("[[", 1) %>% | ||
do.call(what = order) | ||
x [x_order] | ||
|
||
#' Version number of R-oldrel | ||
#' | ||
#' R-oldrel is the latest version of the previous minor version. | ||
#' We extract version numbers from the R SVN repository tags. | ||
#' | ||
#' @inheritParams r_versions | ||
#' | ||
#' @export | ||
#' @examples | ||
#' r_oldrel() | ||
|
||
r_oldrel <- function(dots = TRUE) { | ||
|
||
versions <- r_versions(dots) | ||
|
||
version_strs <- package_version(names(versions)) | ||
|
||
major <- version_strs$major | ||
minor <- version_strs$minor | ||
major_minor <- paste(major, sep = ".", minor) | ||
|
||
latest <- tail(major_minor, 1) | ||
tail(versions[ major_minor != latest ], 1)[[1]] | ||
} | ||
|
||
. <- "Looking for job offers" | ||
|
||
get_props <- function(x) unname(x[["propstat"]][["prop"]]) | ||
|
||
|
||
get_tags <- function(x) unname(xmlValue(x[["getetag"]])) | ||
|
||
|
||
get_dates <- function(x) unname(xmlValue(x[["creationdate"]])) |
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
Oops, something went wrong.