[Rd] r-release, r-oldrel

Gábor Csárdi csardi.gabor at gmail.com
Thu Nov 20 22:43:22 CET 2014


On Fri, Nov 7, 2014 at 6:09 AM, peter dalgaard <pdalgd at gmail.com> wrote:
[...]
> Now you got me curious... this seems to do the job of finding the last release of all major.minor series:
>
> tb <- read.table(text=system("svn ls -v http://svn.r-project.org/R/tags", intern=TRUE))
> names(tb) <- c("rev","au","m","d","y.or.time", "tag")
> ix <- grep(x=tb$tag,pattern="^R-[0-9]+-[0-9]")
> tb <- tb[ix,c("rev", "tag")]
> v.str <- as.character(tb$tag)[order(tb$rev)]
> versions <- data.frame(do.call(rbind,strsplit(v.str,"[-/]+"))[,-1],stringsAsFactors=FALSE)
> names(versions) <- c("major","minor","patch")
> maj.min <- paste(versions$major,versions$minor, sep=".")
> maj.min <- factor(maj.min,levels=unique(maj.min))
> unsplit(lapply(split(versions, maj.min),tail,1),unique(maj.min))

Thanks, awesome! As I needed something that does not call svn (might
not be installed), I went with querying the list via webdav. This is
my final solution, for the records. It is lengthy, though.

library(magrittr)
library(RCurl)
library(XML)

## Get the tag info from SVN
xtags <- getURLContent(
  "http://svn.r-project.org/R/tags/",
  customrequest = "PROPFIND",
  httpheader=c("Depth"="1")
) %>%
  xmlParse() %>%
  xmlRoot() %>%
  xmlChildren()

## 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)
}

## Sort version numbers
sort_tags <- function(x) {
  x_order <- x %>%
    split_versions() %>%
    apply(1, list) %>%
    lapply("[[", 1) %>%
    do.call(what = order)
  x [x_order]
}

## Extract versions numbers from XML and sort them
versions <- xtags %>%
  lapply(xpathApply, "*[local-name()='href']") %>%
  sapply("[[", 1) %>%
  sapply(xmlValue) %>%
  unname() %>%
  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()

Thanks again,
Gabor


> -pd

[...]



More information about the R-devel mailing list