Tal Galili
2011-Apr-18 06:51 UTC
[Rd] Patching "update.packages" to enable updating of only a user defined subset of packages
Hello dear R developers, I recently found out that it is not possible to limit update.packages() to update only a few packages at a time. The patch offered simply adds a 'subset' parameter and the statement bounded within "if(!missing(subset))" to implement it. The code is pasted bellow (and also attached as an .r file). Might this patch be considered valuable to be added to R? (in the code bellow I called the function "update.packages.2" so to not mask the original update.packages) With much respect, Tal ############################### update.packages.2 <- function (lib.loc = NULL, repos = getOption("repos"), contriburl contrib.url(repos, type), method, instlib = NULL, ask = TRUE, available = NULL, oldPkgs = NULL, ..., checkBuilt = FALSE, type = getOption("pkgType"), subset) { force(ask) text.select <- function(old) { update <- NULL for (k in seq_len(nrow(old))) { cat(old[k, "Package"], ":\n", "Version", old[k, "Installed"], "installed in", old[k, "LibPath"], if (checkBuilt) paste("built under R", old[k, "Built"]), "\n", "Version", old[k, "ReposVer"], "available at", simplifyRepos(old[k, "Repository"], type)) cat("\n") answer <- substr(readline("Update (y/N/c)? "), 1L, 1L) if (answer == "c" | answer == "C") { cat("cancelled by user\n") return(invisible()) } if (answer == "y" | answer == "Y") update <- rbind(update, old[k, ]) } update } if (is.null(lib.loc)) lib.loc <- .libPaths() if (is.null(available)) available <- available.packages(contriburl = contriburl, method = method) if (is.null(oldPkgs)) { oldPkgs <- old.packages(lib.loc = lib.loc, contriburl = contriburl, method = method, available = available, checkBuilt = checkBuilt) if (is.null(oldPkgs)) return(invisible()) } else if (!(is.matrix(oldPkgs) && is.character(oldPkgs))) stop("invalid 'oldPkgs'; must be a result from old.packages()") if(!missing(subset)) # if the user uses 'subset' { if(mode(subset) != "character") stop("'subset' must be a character vector (with names of packages)") ss <- oldPkgs[,"Package"] %in% subset # are there any old packages that the user would have liked to update? if(!any(ss)) { cat("There are no available new updates for the packages you have entered \n ") return(invisible()) } # if not - then we can end the function here oldPkgs <- oldPkgs[ss,] # else - we can go on, but this time only use a subset of the oldPkgs. if(sum(ss)==1) oldPkgs <- t(oldPkgs) # in case there is only 1 package to update, make sure the object "oldPkgs" is of the correct form (6 columns instead of 1 vector) } update <- if (is.character(ask) && ask == "graphics") { if (.Platform$OS.type == "windows" || .Platform$GUI = "AQUA" || (capabilities("tcltk") && capabilities("X11"))) { k <- select.list(oldPkgs[, 1L], oldPkgs[, 1L], multiple = TRUE, title = "Packages to be updated", graphics = TRUE) oldPkgs[match(k, oldPkgs[, 1L]), , drop = FALSE] } else text.select(oldPkgs) } else if (isTRUE(ask)) text.select(oldPkgs) else oldPkgs if (length(update)) { if (is.null(instlib)) instlib <- update[, "LibPath"] libs <- unique(instlib) for (l in libs) install.packages(update[instlib == l, "Package"], l, contriburl = contriburl, method = method, available = available, ..., type = type) } } # Example: # old.packages() # update.packages.2(subset = "MASS") ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili at gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ----------------------------------------------------------------------------------------------
Sharpie
2011-Apr-20 17:34 UTC
[Rd] Patching "update.packages" to enable updating of only a user defined subset of packages
Tal Galili wrote:> > Hello dear R developers, > > I recently found out that it is not possible to limit update.packages() to > update only a few packages at a time. > > The patch offered simply adds a 'subset' parameter and the statement > bounded > within "if(!missing(subset))" to implement it. > The code is pasted bellow (and also attached as an .r file). > > Might this patch be considered valuable to be added to R? > > > (in the code bellow I called the function "update.packages.2" so to not > mask > the original update.packages) > > > With much respect, > Tal >Hi Tal, I think if you pass a character vector in the `oldPkgs` argument of update.packages, it will only consider packages in that list for updating. -Charlie ----- Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Patching-update-packages-to-enable-updating-of-only-a-user-defined-subset-of-packages-tp3456738p3463670.html Sent from the R devel mailing list archive at Nabble.com.
Seemingly Similar Threads
- errors from update.packages()
- Update packages problem
- update.packages(checkBuilt = TRUE) fails in updating rpanel_1.1-1 due to missing package BWidget
- install.packages() / update.packages() sometimes outputs to stdout and sometimes to stderr [and menu() & readline()]
- Updating packages after install of r-base 2.6.2: cant update rgl