#### is source(*, local=TRUE)d from /u/sfs/R/Rprofile -- #### at each regular R startup at SfS libPIns <- function(nlib, beforeLib, msgTxt, doWarn = TRUE, MSG = if(interactive()) message else function(...) invisible()) { ## Purpose: Insert a directory into .libPaths() *before* another one ## ---------------------------------------------------------------- ## Arguments: nlib: The library directory to insert ## beforeLib: (grep-pattern of an) entry in current .libPaths() ## msgTxt: optional message text about the insertion ## ---------------------------------------------------------------- ## Author: Martin Maechler, 2006 lp <- .libPaths() if(file.exists(nlib)) { if(!any(nlib == lp)) { if(length({fl <- list.files(nlib); fl[fl != "R.css"]})) { ## only if the library contains any packages : if(!missing(msgTxt) && is.character(msgTxt)) MSG("extending .libPaths() ", msgTxt," ...") ni <- length(iL <- grep(paste(beforeLib,"$",sep=''), lp)) if(ni != 1) { warning(".libPaths() contains ", if(ni>1) "more" else "no", " entries matching ",sQuote(beforeLib)) iL <- if(ni > 1) iL[1] else length(lp) MSG("Inserting before position ", iL," ..") } ii <- 1:length(lp) .libPaths(c(lp[ii < iL], nlib, lp[ii >= iL])) } else if(doWarn) { MSG("library ", sQuote(nlib), " with no packages *not* added to lib path") } } } else if(doWarn) warning(nlib, " is not an existing directory") }