After I installed RStudio, I ran:
library()
Warning message: libraries '/usr/local/lib/R/site-library', 'usr/lib/R/site-library' contain no packages
Then I input:
.libPaths()
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
How can I remove [2] and [3] to prevent the warning message appear again?
Expected output:
.libPaths()
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[4] "/usr/lib/R/library"
First thing to do is read the manpage on it (?.libPaths
), and you'll see:
'.libPaths' is used for getting or setting the library trees that R knows about (and hence uses when looking for packages). If called with argument ‘new’, the library search path is set to the existing directories in
unique(c(new, .Library.site, .Library))
and this is returned. If given no argument, a character vector with the currently active library trees is returned.
(emphasis added). This should clue us in to wonder what .Library.site
holds. Oddly enough, it holds system-wide (ergo "site") library paths that "should" always be kept, so they are always maintained.
It further goes on to say:
'.Library.site' can be set via the environment variable 'R_LIBS_SITE' (as a non-empty semicolon-separated list of library trees).
So one way to fix it is to give it an empty string when you start R (cannot be done from within R):
# in bash on the command line:
$ R_LIBS_SITE=" " R
# in R
R> .libPaths()
[1] "/usr/lib/R/library"
The way to get this to work with RStudio is by creating a ~/.Renviron
file with at least the following:
R_LIBS_SITE=" "
That done, you should not have to do anything further to remove the secondary site library paths from .libPaths()
:
R> .libPaths()
[1] "/usr/lib/R/library"
Assuming you're doing the following:
R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
If you want to correct it after you've done this, then just do:
R> .libPaths( c(.libPaths()[c(1,4)]) )
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"
Alternatively, you can do it this way the first time (i.e., while it still has three elements, two of which are not good for you):
R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()[3]))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"
There is certainly a way to filter the paths programmatically instead of blindly taking the 3rd element, but this should work for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With