From jfox at mcmaster.ca  Sat Apr 18 15:33:39 2009
From: jfox at mcmaster.ca (John Fox)
Date: Sat, 18 Apr 2009 09:33:39 -0400
Subject: [Rd] wish list: automatic package installation
Message-ID: <002101c9c02a$50994070$f1cbc150$@ca>

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



[Rd] wish list: automatic package installation
John Fox