#! /usr/local/bin/Rscript Sys.unsetenv("R_HOME") rec <- c("MASS", "Matrix", "boot", "class", "cluster", "lattice", "mgcv", "nlme", "nnet", "rpart", "spatial", "survival") args <- commandArgs(TRUE) .libPaths(args[1]) old <- readRDS(args[2]) old <- as.data.frame(old, stringsAsFactors = FALSE) new <- installed.packages(args[1])[, c("Package", "Version")] new <- as.data.frame(new, stringsAsFactors = FALSE) both <- merge(old, new, by = "Package") updated <- with(both, Package[Version.x != Version.y]) ## new packages might be in Suggests added <- setdiff(row.names(new), row.names(old)) ## and removed packages might have (a few) dependents removed <- setdiff(row.names(old), row.names(new)) if(!length(c(updated, added, removed))) { message("no changed packages") q("no") } cur <- gsub("[.]out", "", dir(dirname(args[2]), patt = "[.]out")) foo <- reinst <- character() changed <- c(updated, added, removed) for (u in changed) { foo0 <- tools::dependsOnPkgs(u, , TRUE) foo00 <- intersect(foo0, cur) if(length(foo00) <= 250L) reinst <- c(reinst, foo00) else { foo1 <- tools::dependsOnPkgs(u, , FALSE) foo1 <- intersect(foo1, cur) if(length(foo1) <= 250L) { reinst <- c(reinst, foo1) message(sprintf("re-installing %d/%d revdeps of %s", length(foo1), length(foo0), sQuote(u))) } else message(sprintf("not re-installing %d revdeps of %s", length(foo0), sQuote(u))) } foo2 <- c(foo0, tools::dependsOnPkgs(c(u, foo0), 'all', FALSE)) foo2 <- intersect(foo2, cur) if(length(foo2) <= 250L) foo <- c(foo, foo2) else { foo1 <- tools::dependsOnPkgs(u, 'all', FALSE) foo1 <- intersect(foo1, cur) if(length(foo1) <= 250L) { foo <- c(foo, foo1) message(sprintf("re-checking %d/%d revdeps of %s", length(foo1), length(foo2), sQuote(u))) } else message(sprintf("not re-checking %d revdeps of %s", length(foo2), sQuote(u))) } } reinst <- sort(unique(reinst)) reinst <- setdiff(reinst, c(changed, rec)) foo <- sort(unique(foo)) foo <- setdiff(foo, rec) if(length(reinst)) { message ("re-installing ", paste(sQuote(reinst), collapse =" ")) unlink(file.path(dirname(args[2]), paste0(reinst, ".log"))) if(length(reinst) > 20L) system("make installn") else system("make install") } if(length(foo)) { message ("re-checking ", paste(sQuote(foo), collapse =" ")) unlink(file.path(dirname(args[2]), paste0(foo, ".out"))) } else message("no re-checking needed")