From hb at biostat.ucsf.edu  Wed Mar 16 04:13:01 2011
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Tue, 15 Mar 2011 20:13:01 -0700
Subject: [Rd] .libPaths() on Windows may return duplicated paths
Message-ID: <AANLkTikU88Pm+4td3_skO8mNVkX8dVdd+gV=HfnA71sS@mail.gmail.com>

In R v2.12.2 patched (2011-03-13 r54787) and also in R v2.13.0 devel
(2011-03-15 r54806), .libPaths() may return the multiple paths
referring to the same "normalized" path name.  Here is an example from
Rterm --vanilla using R v2.12.2 patched:

> paths <- .libPaths(c("C:/", "C:\\"))
> paths
[1] "C:/"
[2] "C:\\"
[3] "C:/PROGRA~1/R/R-2.13.0dev/library"

The reason is that .libPaths() does not detect paths[1] and paths[2]
to be "equal";

> .libPaths
function (new)
{
    if (!missing(new)) {
        new <- Sys.glob(path.expand(new))
        paths <- unique(path.expand(c(new, .Library.site, .Library)))
        .lib.loc <<- paths[file.info(paths)$isdir %in% TRUE]
    }
    else .lib.loc
}

One solution would be to replace:

  paths <- unique(path.expand(c(new, .Library.site, .Library)))

with

  paths <- path.expand(c(new, .Library.site, .Library))
  paths <- utils::normalizePath(paths)
  paths <- unique(paths)

This would obviously not work because this would make .libPaths()
depend on the utils package as standing.  Migrating normalizePath() to
the 'base' package would be one solution.


Finally, this causes update.packages() to try to download and install
the same package multiple times, e.g.

> .libPaths()
[1] "C:\\Users\\hb/R/win-library/2.12"
[2] "C:/PROGRA~1/R/R-2.12.2patched/library"
[3] "C:\\Users\\hb\\R\\win-library\\2.12"

> update.packages()
digest :
 Version 0.4.1 installed in C:\Users\hb/R/win-library/2.12
 Version 0.4.2 available at http://cran.stat.ucla.edu
Update (y/N/c)?  y
digest :
 Version 0.4.1 installed in C:\Users\hb\R\win-library\2.12
 Version 0.4.2 available at http://cran.stat.ucla.edu
Update (y/N/c)?  y
...

Obviously, I know how to fix/avoid this myself, but I figured it is
more generic if .libPaths() does it for everyone.

/Henrik



[Rd] .libPaths() on Windows may return duplicated paths
Henrik Bengtsson