[Rd] wish list: automatic package installation

John Fox jfox at mcmaster.ca
Sat Apr 18 15:33:39 CEST 2009


Dear list members,

The release of R 2.9.0, reminds me of a long-standing nit that I have to
pick. I prefer not to transfer and update all of the packages in my old
library, because I see a new release of R as an opportunity to start with a
clean slate. I'd rather install packages as I need them. My personal
solution is to use the following function in place of library():

package <- function(package, dependencies=TRUE, ...){
     package <- as.character(substitute(package))
     if (!(package %in% .packages(all.available=TRUE)))
        install.packages(package, dependencies=dependencies)
    library(package, character.only=TRUE, ...)
    }

I'm sure that this function could be improved, and possibly I've missed a
facility that's already available. If not, it would be nice if the library()
command automatically tried to download and install missing packages
(perhaps if an option is set).

Regards,
 John

------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox



More information about the R-devel mailing list