cloudscomputes
cloudscomputes

Reputation: 1484

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?

Upvotes: 1

Views: 251

Answers (2)

cloudscomputes
cloudscomputes

Reputation: 1484

They are supposed to be the same

However in windows you can't use .Library's value directly to locate the folder.

But when I create folder using either libpaths and .Library, the result located in the same folder~

Since I think this is helpful so I post my answer for my own question here.

Upvotes: 0

user10191355
user10191355

Reputation:

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.

Upvotes: 1

Related Questions