[Rd] speedbump in library

Peter Haverty haverty.peter at gene.com
Thu Jan 22 19:25:17 CET 2015


Hi all,

Profiling turned up a bit of a speedbump in the library function. I
submitted a patch to the R bug tracker as bug 16168 and I've also
included it below. The alternate code is simpler and easier to
read/maintain, I believe.  Any thoughts on other ways to write this?

Index: src/library/base/R/library.R
===================================================================
--- src/library/base/R/library.R    (revision 67578)
+++ src/library/base/R/library.R    (working copy)
@@ -688,18 +688,8 @@
     out <- character()

     for(pkg in package) {
-        paths <- character()
-        for(lib in lib.loc) {
-            dirs <- list.files(lib,
-                               pattern = paste0("^", pkg, "$"),
-                               full.names = TRUE)
-            ## Note that we cannot use tools::file_test() here, as
-            ## cyclic namespace dependencies are not supported.  Argh.
-            paths <- c(paths,
-                       dirs[dir.exists(dirs) &
-                            file.exists(file.path(dirs,
-                                                  "DESCRIPTION"))])
-        }
+        paths <- file.path(lib.loc, pkg)
+        paths <- paths[ file.exists(file.path(paths, "DESCRIPTION")) ]
         if(use_loaded && pkg %in% loadedNamespaces()) {
             dir <- if (pkg == "base") system.file()
             else getNamespaceInfo(pkg, "path")

Pete

____________________
Peter M. Haverty, Ph.D.
Genentech, Inc.
phaverty at gene.com



More information about the R-devel mailing list