Andrew Kirk
Andrew Kirk

Reputation: 2157

How to make a user's R library available to another user (Linux)

I have R 3.3 installed on a PC running Linux Mint 17.1 Rebecca (64-bit). Mostly I use it from my normal user account 'andrew', but sometimes I have to use it on confidential data files that are only available through a VPN, and I have to start R as root in order for that to work.

This works fine, except until today when I tried to use package ggplot2 from R on root and the library(ggplot2) command told me it was not installed, even though it is installed for the andrew account on this PC.

So I tried to install ggplot2 from the root account, but it failed with one of the dependencies. I could try to troubleshoot that failure but last time I did that it was a long and painful process. I should just be able to use the version that is already installed for 'andrew'.

Executing the command library() on both root and andrew, I see that ggplot2 is installed in library

/home/andrew/R/x86_64-pc-linux-gnu-library/3.3

which is listed as available for andrew but not for root.

I would like to do some action that makes that library also available to root. When I searched for suggestions about this, they recommended changing the .Renviron or .Rprofile file in the home directory, which I believe is /root under this installation. However no files of that name exist anywhere under that directory. Nor do they exist anywhere in the working directory I am using on the VPN.

Can anybody please suggest how to make the library available to root?

Thank you

Andrew

Upvotes: 0

Views: 2400

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368439

This something I fairly strongly believe it and even tried to set up for the Debian and Ubuntu packages (though it is not currently active).

The key is your value of the library path, ie do

.libPaths()

on your box, and you are likely to see the dreaded directory below $HOME as the first spot. And unless you say otherwise installations will go to the first spot, hiding "your" packages from other users.

Now, you can do two things:

  1. Explicitly install into a different directory. See the options for install.packages()
  2. Alter the library path.

I usually choose option 2 on our machines at work. Here is what we have in ${R_HOME}/etc/Renviron (still showing the comment I added to the R package thirteen (!!) years ago):

#R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.3'}
#R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.3/library'}

# edd Apr 2003  Allow local install in /usr/local, also add a directory for
#               Debian packaged CRAN packages, and finally the default dir 
# edd Jul 2007  Now use R_LIBS_SITE, not R_LIBS
R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}

You see that R_LIBS_USER is commented-out, and R_LIBS_SITE default to the standard location below /usr/local.

Then:

R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"       "/usr/lib/R/library"           
R> 

and packages go into the directory visible to all users (and we make the directory is group-writeable for the proper users).

Upvotes: 5

Related Questions