From haverty.peter at gene.com  Thu Jan 22 19:25:17 2015
From: haverty.peter at gene.com (Peter Haverty)
Date: Thu, 22 Jan 2015 10:25:17 -0800
Subject: [Rd] speedbump in library
Message-ID: <CAGh0NYoAgB-ydT2j0eynAcRMefmL6C3m81dD-a6ZfDmN3kO+tw@mail.gmail.com>

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



[Rd] speedbump in library
Peter Haverty