Nutle Nutle - 2 months ago 7
R Question

RStudio: using different package versions for each .Rproj

I have a few older R projects I'm working with, which are dependent on several currently deprecated (or heavily modified) packages. In order for everything to work smoothly I use older versions of those packages, which I have saved in another folder and load up manually to

%userprofile%\documents\R\win-library\3.3
when necessary. However, this is not convenient, especially if I want to run multiple projects simultaneously, some of which requires the new and updated versions of the packages.

My question - is there a way to specify custom directories for each
.Rproj
from which it would take and load the libraries?

Answer

You can solve this much simpler:

  1. Have a top-level directory for each project, call projA, projB, ...
  2. Within each of these, create a directory libs/, say.
  3. And within each of these directories have a file .Rprofile with a single assignment such as .libPaths("./libs")

Now when you start R in the different project directories, each will a separate library directory preceding the path, allowing you to place per-projects overrides there.

In an nutshell, the approach outlines here allows you to keep the local and modified packages around as you please. (You can even assign common directories via .libPaths() if you so choose.)

The nice things is that this will

  1. work with any R invocation, batch or GUI or RStudio or shiny or ...
  2. does not depend on any other tools, and hence
  3. does not rely on RStudio or .Rprof files -- though you are free to use RStudio as well.

As so often, Base R is there for you.

Comments