Installing R packages without admin rights on MS Windows

Photo: Markus Gesmann
Is there a life outside the office?
Photo: Markus Gesmann

It is not unusual that you will not have admin rights in an IT controlled office environment. But then again the limitations set by the IT department can spark of some creativity. And I have to admit that I enjoy this kind of troubleshooting.

The other day I ended up in front of a Windows PC with R installed, but a locked down "C:\Programme Files" folder. That ment that R couldn't install any packages into the default directory "C:\Programme Files\R\R-X.Y.Z\library" (replace R-X.Y.Z with the version number of R installed).

Never-mind, there is an option for that, the libs argument in the install.packages function. However, I have to use the same argument also in the library statement then as well. Fair enough, yet it is more convenient to set the directory somewhere globally.

First of all I decided that I wanted to install my R packages into C:\Users\MyNAME\R, a folder to which I had read/write access (replace MyNAME, or the whole path with what works for you). The R command .libPaths(c("C:\\Users\\MyNAME\\R", .libPaths())) will make this directory the default directory for any additional packages I may want to install, and as it is put at the front of my search path, library will find them first as well.

The next step is to enable R to execute the above command at start up. For that I created the R file C:\Users\MyNAME\R\Rconfigure_default.R with the following content:

Finally I added a new shortcut to Rgui.exe to my desktop with the target set to:

"C:\Program Files\R\R-2.X.Y\bin\i386\Rgui.exe" R_PROFILE_USER="C:\Users\MyNAME\R\Rconfigure_default.r"

Job done. R will happily install any new packages locally and find them as well when I use library or require. For more information see also the R FAQs.


cmdlintips said...

Nice.. Here my post on how to install packages locally in from terminal

andrezalook said...

what if the problem is to download the packages?
I have no permission to download stuff.

Markus Gesmann said...

Well, talk to the IT guys, buy them a coffee or beer, try to understand why the have locked down your rights. What are the risks? What are the business benefits on the other hand if you were able to install packages. Would those business benefits outweigh the risks? If they do, then you are in a pretty good position to negotiate.

andrezalook said...

ahaha, ok (:

Richard Todd said...

Lloyd's IT giving you a hard time? Good guide this, insurance needs to wake up and embrace creativity.

Danièle said...

How would you proceed with R Studio?
I am newbie at R and have no adminsitration rights which does not help!

Markus Gesmann said...

Alternatively you can store the above code in the .Rprofile located in your working directory. RStudio will read this file on start up. Read the RStduio documentation for more details:

Christian Kaas said...

Thanks Markus
I googled my way through a lot of failed attempts before finding this site. This was exactly what i needed. Thanks for putting this on your blog!

Post a Comment