4

I have read the R FAQS and other posts but I am a bit confused and would be grateful to know whether I did everything correctly.

In Windows, in order to modify the default library folder I created a file Renviron.site and put inside E:/Programs/R-3.3.0/etc. The file has only one line saying

R_LIBS=E:/Rlibrary

When I open R and run .libPaths() I see E:/Rlibrary as [1] and the default R library E:/Programs/R-3.3.0/library as [2].

This should mean that from now on all packages I will install will go in E:/Rlibrary but at the same time I will be able to load and use both packages in this folder and those in the default location. Am I correct?

3
  • 2
    This is correct, and also very easy to verify. install.package has a lib parameter which you can use to specify which folder to install to. Commented May 20, 2016 at 19:37
  • Thank you. I was under the impression there are many different possibilities and wanted to make sure the one I implemented is fine and does not cause any trouble when using libraries installed in different folders and so on.
    – Cla
    Commented May 21, 2016 at 6:17
  • @warmoverflow If I may ask for further clarification: In a Windows PC where R-3.2.1 was already installed, in the list of R versions to use Rstudio shows both [64-bit] E:\Programs\R-3.2.1 and [64-bit] E:\Programs\R-32~1.1. Also, the last item in the list returned by searchpaths() is "E:/Programs/R-32~1.1/library/base" . I am confused, why are the two path notations mixed?
    – Cla
    Commented Jun 12, 2016 at 12:42

1 Answer 1

3

When you load a package via library, it will go through each directory in .libPaths() in turn to find the required package. If the package hasn't been found, you will get an error. This means you can have multiple versions of a package (in different directories), but the package that will be used is determined by the order of .libPaths().

Regarding how .libPaths() is constructed, from ?.R_LIBS

The library search path is initialized at startup from the environment variable 'R_LIBS' (which should be a colon-separated list of directories at which R library trees are rooted) followed by those in environment variable 'R_LIBS_USER'. Only directories which exist at the time will be included.

Not the answer you're looking for? Browse other questions tagged or ask your own question.