R 3.4.1 personal library location
R 3.4.1 ‘Single Candle’ was released on June 30, 2017. Our group is preparing to provide an R workshop at our societal meeting this summer, so I’m tryingot keep up to date with the R releases. Installation on my work Ubuntu 16.04 LTS machine appeared to go smoothly. However, upon trying to install packages I received the following error.
Warning in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl, :
'lib = "/usr/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (y/n) y
Would you like to create a personal library
NA
to install packages into? (y/n) y
Error in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl, :
unable to create ‘NA’
This seemed odd to me because I am used to R creating a personal library as a child of my home directory. Here it is attempting to use ’NA“, which fails. With a little Googling I found the issue posted here on stack overflow, where Dirk Eddelbuettel has replied, and on Debian Bug report logs, where Dirk has also replied. I also found this post on stackoverflow useful, which is also by Dirk, because it explains the recommendation for where packages should be installed on a Unix system. Here I explain how I used information from these links to start installing packages on my system.
My system
First off its important to state that the system I’m discussing today is a work system on a work network, as opposed to a personal system. That means I need to avoid interrupting any network settings or else I’ll have to contact IT to get them to help me fix it. Fortunately, our netowrk is a Windows network, so I’m really more of an exception which may give me more flexibility than others.
My .libPaths()
As suggested by Dirk I checked the permissions of my /usr/local/lib/R/site-library
.
$ ls -l /usr/local/lib/R/
total 4
drwxrwsr-x 2 root staff 4096 Aug 5 2016 site-library
Its owned by root
and group memebership belongs to staff
. I can check and see that I’m not a part of staff
, which explains the error.
$ id
uid=1142428492(knausb) gid=1142424065(domain^users) groups=1142424065(domain^users),126(vboxusers),1142425304(grunwald-lab),1142428469(linux-users),1142429799(certsvc_dcom_access),1142429897(linux^admins)
Because I’m not actually the system administrator, I do not know a lot about the existing groups. I found this post which explains how I can query for the members of groups on my system. After creating the script I use the following to determine that there are no members of this group.
perl -T list_group_members.pl staff
This leads me to believe I can change it’s group ownership with no consequences.
$ sudo chgrp domain^users /usr/local/lib/R/site-library/
$ ls -l /usr/local/lib/R/
total 4
drwxrwsr-x 103 root domain^users 4096 Jul 6 10:16 site-library
Now I, and presumedly other users on this system if there are any, can install packages into /usr/local/lib/R/site-library/
. Which means I have some package installations to work on.
Setting R_LIBS_USER
The above appears to be the ‘suggested’ manner to address this issue. However, there are options if the above does not suit you. For example, if you do not have administrator priviledges on the system you are working on, you will not be able to implement the above method. An alternate solution is to modify your Renviron
file to set R_LIBS_USER
. This can usually be found here:
/usr/lib/R/etc/Renviron
You should be able to locate the following lines.
# edd Jun 2017 Comment-out R_LIBS_USER
#R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
##R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.4/library'}
If you uncomment this so that it appears as follows,
# edd Jun 2017 Comment-out R_LIBS_USER
R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
##R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.4/library'}
and restart R, it should restore the behavior you are familiar with where a personal library is created at the indicated path. However, this still requires administrator privileges. If you add:
R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
to your ~/.Renviron
file (where ‘~’ is your home directory). If you do not have this file already, you can create it. You should now gain behavior similar to the previous solution except that this should only affect your account as opposed to all system accounts. Happy package installing!