Changing packages directory in Rprofile

986 views Asked by At

I have a project called "R installation info" And a sub directory called "Project Packages".

I am trying to configure R in a manner that when I Install a new package it will be installed to "Project Packages".
Also when I have an R session with that project I would like to see in RStudio in Packages folder only the packages that were installed in "Project Packages".

I created an Rprofile file in the project directory And put the following lines in it:

.libPaths = paste0(getwd(),"/","Project Packages")
Sys.setenv(R_LIBS_USER = paste0(getwd(),"/","Project Packages"))

However when I started a new session with that project And installed a new package like that:

> install.packages("magrittr")
Installing package into ‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/magrittr_1.5.zip'
Content type 'application/zip' length 155955 bytes (152 KB)
downloaded 152 KB

package ‘magrittr’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\Rafael Zanzoori\AppData\Local\Temp\RtmpOQWtgi\downloaded_packages

I see that the package was installed to a different directory from what I specified:

‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’

Instead of:

C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages

We can see from the following that the path for new packages is

> .libPaths
[1] "C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages"
> Sys.getenv("R_LIBS_USER")
[1] "C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages"

Also when I click on "install" button on package folder in RStudio I see in "Install to Library" textbox : ‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’

Different default path

Can you please help me understand why my Rprofile definitions for installing packages are ignored by R and how to fix it?

I tried to search for relevant posts but could not find anything that will help

Thanks Rafael

1

There are 1 answers

1
Rafael Zanzoori On

Finally i managed to solve the problem by renaming ‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’

to something else. Since then R is using the definitions in my project's Rprofile.

I don't know what made R to override my project Rprofile since i didn't have any other Rprofile

But changing the old directory name solved the problem