[Rd] require is to suggests as what is to imports?
Hadley Wickham
hadley at rice.edu
Wed Aug 25 14:32:33 CEST 2010
> But thereby clobber your users with the run-time cost of
> installed.packages() (which can take several minutes on some Windows
> systems, and just took ca 12secs on my fastest Linux server with 3000
> packages installed). If you want to take this route (is a package
> installed?), see the 'Note' on ?installed.packages for better alternatives.
On that note, I wrote a version of installed.packages() which runs
quite a bit faster on my computer:
installed_packages <- function() {
paths <- unlist(lapply(.libPaths(), dir, full.names = TRUE))
desc <- file.path(paths, "DESCRIPTION")
desc <- desc[file.exists(desc)]
dcf <- lapply(desc, read.dcf, fields = c("Package", "Title", "Version"))
packages <- as.data.frame(do.call("rbind", dcf), stringsAsFactors = FALSE)
packages$status <- ifelse(packages$Package %in% .packages(),
"loaded", "installed")
class(packages) <- c("packages", class(packages))
packages[order(packages$Package), ]
}
It probably runs faster because I've eliminated some features, and
it's probably not worth spending much time optimising such a rarely
used function, but there it is for what it's worth.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-devel
mailing list