Installing R packages without admin rights on MS Windows

Office building in Brüssel. Photo Markus Gesmann

Office building in Brüssel. 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:Files” folder. That meant that R couldn’t install any packages into the default directory “C:Files-X.Y.Z” (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:, 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:_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.

Citation

For attribution, please cite this work as:

Markus Gesmann (Apr 26, 2012) Installing R packages without admin rights on MS Windows. Retrieved from https://magesblog.com/post/2012-04-26-installing-r-packages-without-admin/

BibTeX citation:

@misc{ 2012-installing-r-packages-without-admin-rights-on-ms-windows,
 author = { Markus Gesmann },
 title = { Installing R packages without admin rights on MS Windows },
 url = { https://magesblog.com/post/2012-04-26-installing-r-packages-without-admin/ },
 year = { 2012 }
 updated = { Apr 26, 2012 }
}

Related