We are running RStudio Server on an AWS-hosted CentOS Linux server. We have multiple users on the server each using RStudio Server. We'd like to have a common path for all users to install packages so that:
- Each user does not need to install every package for their RStudio user profile
- If one person updates a package, every user will be using the updated
What is the best procedure to do this?
My proposed solution was the following, but it failed:
Save a list of my existing user packages:
> save.pkg.list <- installed.packages()[is.na(installed.packages()[ , "Priority"]), 1]
> save(save.pkg.list, file="pkglist.Rdata")
Remove user packages:
> remove.packages(save.pkg.list)
Then, my idea was to install the packages from save.pkg.list
into a folder under root. There was already what seemed to be a shared folder /usr/share/R/library
which contained one package in my library path:
.libPaths() [1] "/home/ursus/R/x86_64-redhat-linux-gnu-library/3.1" "/usr/lib64/R/library" "/usr/share/R/library"
To test it out, I attempted to install one package into the shared folder and see if other users on the server could use it in their R instances. The installation failed, most probably because it is under root and I'm assuming I need to use sudo privileges (which I have) but not sure how to pass those to R for the package installation process:
install.packages("dlm", lib = "/usr/share/R/library") Warning in install.packages : 'lib = "/usr/share/R/library"' is not writable
Eventually, I'm assuming there need to be some changes to the R_LIBS_SITE
and R_LIBS_USER
environment variables or something like that to control the default package installation / loading behavior. But, I'm not there yet.
I've never tried this, but I don't see why this wouldn't work:
You can use
.libPaths()
to set the library dir (not only to get it), so why don't you have everyone use a common directory that's writeable by everyone as the libpath? Every user can put in their.Rprofile
something likeThen that path will be the default place where everyone installs/retrieves packages from.
One problem with this approach is that people will still have their original libPath per person, so if they're trying to update an existing package, it'll update their own version. You can overcome that by setting the libpath to ONLY the new path instead of appending to it.
Note that this can sometimes have bad consequences, sometimes person A's code depends on a certain version of a package, then person B updates the package, then person A runs his code again 5 minutes later and all of a sudden it breaks and they have absolutely no idea why.