Installing R packages without admin rights on MS Windows

[This article was first published on mages' blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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. But then I have to use the same argument also in the library statement. 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.

To leave a comment for the author, please follow the link and comment on their blog: mages' blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)