From csardi.gabor at gmail.com  Thu Nov 20 22:43:22 2014
From: csardi.gabor at gmail.com (=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=)
Date: Thu, 20 Nov 2014 16:43:22 -0500
Subject: [Rd] r-release, r-oldrel
In-Reply-To: <C6E7D4D9-4049-404F-846C-C50961DE0E1A@gmail.com>
References: <CABtg=Kn2fDXQedu=KaXpEx21hSLu=HqDB=aE_QthPvs8LCSzuw@mail.gmail.com>
	<545BF7F3.4000708@statistik.tu-dortmund.de>
	<CABtg=Knonx3oAc+Xo0LN5Y4PYoSUKU-NRaKEusg6rMU1KO406Q@mail.gmail.com>
	<545BFA1A.2060008@statistik.tu-dortmund.de>
	<C6E7D4D9-4049-404F-846C-C50961DE0E1A@gmail.com>
Message-ID: <CABtg=K=VZ7RZvtLqv=A0ai4nmjsqVc=iDA+UJwvAcE94QdJdAg@mail.gmail.com>

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

[...]



[Rd] r-release, r-oldrel
=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=