From e4a23725616d23cab1b7b303f54fe638803e4c96 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Mon, 25 Jul 2016 07:59:20 -0700 Subject: [PATCH] pkgtest: slight refactor so --list-versions works correctly with --count-daily --- .../r/install.cran.packages.R | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/com.oracle.truffle.r.test.cran/r/install.cran.packages.R b/com.oracle.truffle.r.test.cran/r/install.cran.packages.R index 21cd5a3d1e..963b7702ad 100644 --- a/com.oracle.truffle.r.test.cran/r/install.cran.packages.R +++ b/com.oracle.truffle.r.test.cran/r/install.cran.packages.R @@ -331,6 +331,7 @@ check.installed.pkgs <- function() { # requested set of candidate packages # sets global variables avail.pkgs and toinstall.pkgs, the latter being # of the same type as avail.pkgs but containing only those packages to install +# returns a vector of package names to install/test get.pkgs <- function() { avail.pkgs <<- available.packages(contriburl=contriburl, type="source") avail.pkgs.rownames <<- rownames(avail.pkgs) @@ -371,7 +372,29 @@ get.pkgs <- function() { } matched.avail.pkgs <- apply(avail.pkgs, 1, match.fun) toinstall.pkgs <<-avail.pkgs[matched.avail.pkgs, , drop=F] - toinstall.pkgs + + if (!is.na(random.count)) { + # install random.count packages taken at random from toinstall.pkgs + test.avail.pkgnames <- rownames(toinstall.pkgs) + rands <- sample(1:length(test.avail.pkgnames)) + test.pkgnames <- character(random.count) + for (i in (1:random.count)) { + test.pkgnames[[i]] <- test.avail.pkgnames[[rands[[i]]]] + } + } else { + test.pkgnames <- rownames(toinstall.pkgs) + if (!is.na(count.daily)) { + # extract count from index given by yday + npkgs <- length(test.pkgnames) + yday <- as.POSIXlt(Sys.Date())$yday + chunk <- as.integer(npkgs / count.daily) + start <- (yday %% chunk) * count.daily + end <- ifelse(start + count.daily > npkgs, npkgs, start + count.daily - 1) + test.pkgnames <- test.pkgnames[start:end] + } + } + + test.pkgnames } # Serially install the packages in pkgnames. @@ -476,36 +499,15 @@ get.blacklist <- function() { # performs the installation, or logs what it would install if dry.run = T do.it <- function() { - get.pkgs() + test.pkgnames <- get.pkgs() if (list.versions) { - for (i in (1:length(rownames(toinstall.pkgs)))) { - pkg <- toinstall.pkgs[i, ] + for (pkgname in test.pkgnames) { + pkg <- toinstall.pkgs[pkgname, ] cat(pkg["Package"], pkg["Version"], paste0(contriburl, "/", pkg["Version"], ".tar.gz"), "\n", sep=",") } } - if (!is.na(random.count)) { - # install random.count packages taken at random from toinstall.pkgs - test.avail.pkgnames <- rownames(toinstall.pkgs) - rands <- sample(1:length(test.avail.pkgnames)) - test.pkgnames <- character(random.count) - for (i in (1:random.count)) { - test.pkgnames[[i]] <- test.avail.pkgnames[[rands[[i]]]] - } - } else { - test.pkgnames <- rownames(toinstall.pkgs) - if (!is.na(count.daily)) { - # extract count from index given by yday - npkgs <- length(test.pkgnames) - yday <- as.POSIXlt(Sys.Date())$yday - chunk <- as.integer(npkgs / count.daily) - start <- (yday %% chunk) * count.daily - end <- ifelse(start + count.daily > npkgs, npkgs, start + count.daily - 1) - test.pkgnames <- test.pkgnames[start:end] - } - } - if (install) { cat("BEGIN package installation\n") install.pkgs(test.pkgnames) -- GitLab