Search code examples
rsystem

R .Library and libpaths() returns different result


libpaths() returns valid result:

"D:/R/R-3.3.3/library"

but .Library returns a result not valid:

"D:/R/R-33~1.3/library"

Is this expected or not?


Solution

  • Using a Mac I also get two different paths:

    .Library
    # [1] "/Library/Frameworks/R.framework/Resources/library"
    
    .libPaths()
    # [1] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
    

    The docs have this to say about .Library (emphasis mine):

    .Library is a character string giving the location of the default library, the ‘library’ subdirectory of R_HOME.

    And this about .libPaths() (emphasis mine):

    .libPaths is used for getting or setting the library trees that R knows about (and hence uses when looking for packages).

    In fact, both paths point to the same directory via different routes because the Resources in the first path is an alias pointing to the same Resources in the second path. The main difference is that Versions in the second path contains multiple directories for different versions (the so-called "library trees that R knows about"). Version 3.6 is currently my default library, which is why .Library also points to it. I assume the same logic applies to Windows.