The solution below will work for unix-like operating systems including Mac OS X.
First, we need a location to install all our packages from now on. This can be any directory, and location of this directory should be indicated in ~/.Renviron file. Let's create that directory now:
mkdir ~/Rlibs
We created Rlibs directory in our home directory. Now, create the .Renviron file in your home directory and enter the following line and save the .Renviron file:
R_LIBS=~/Rlibs
We can now start R and install any library. The libraries will be installed to ~/Rlibs, and when we update R, R will still look for libraries in ~/Rlibs directory so we don't need to re-install the libraries. However, we will need to update the libraries in ~/Rlibs directory to their most recent versions. All we need to do is to run update.packages() in R console, and the libraries will be updated.
You can also update Bioconductor package as follows (this probably works with newer versions of Bioconductor):
source("http://bioconductor.org/biocLite.R")
biocLite("BiocUpgrade")
EDIT:
see here for setting environment variables in Windows
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-set-environment-variables_003f
Thank you very much. This is very useful advice indeed!
ReplyDeleteWhat operating system are you using and how are you updating R? I use Ubuntu and just update R from the Ubuntu CRAN repository or the RutteR Launchpad PPA and I never have an issue with having to reload packages.
ReplyDeleteI use Mac OS X or RHEL 5 which I don't have root access. It is possible there are easier ways to update R on those systems, but this is what I'm using at the moment.
ReplyDeleteThanks. Something that has frustrated me in the past but given it's an irregular occurence I haven't hunted out a solution. Will set this up :)
ReplyDeleteis there also a solution for Windows?
ReplyDeleteAfter installing a new version of R on Windows, I just copy the "library" directory of the old R installation and overwrite the "library" directory of the new R installtion.
DeleteIt's always worked for me...
Ravi
check this for a windows solution
ReplyDeletehttp://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-set-environment-variables_003f
Hi l2n,
ReplyDeleteI've tried this, and I get:
> .libPaths()
[1] "/Library/Frameworks/R.framework/Rlib" "/Library/Frameworks/R.framework/Versions/2.15/Resources/library"
[3] "/Applications/RStudio.app/Contents/Resources/R/library"
With [1] being the directory I made. However running update.packages() gives me a bunch of these:
Warning: package 'MASS' in library '/Library/Frameworks/R.framework/Versions/2.15/Resources/library' will not be updated
So it's not updating the packages in the other libraries. Have you come across this?
Hi nzcoops,
DeleteI just tried this and I have core packages installed in /Library/Frameworks/R.framework/Versions/2.15/Resources/library and it worked. I had version 7.3-18 of MASS package installed in that location, now I have version 7.3-19. Didn't get a warning during that process. My .libPaths() show:
[1] "/Users/l2n/RLibs"
[2] "/Library/Frameworks/R.framework/Versions/2.15/Resources/library"
Cheers. I don't fully understand this, but it seems update.packages() updates packages at all locations in .libPaths(), but install.packages() only installs (by default) to the first element of .libPaths(). I removed the 7 packages giving that error from my .../2.15/Resources/library and I no longer get the warning. Still, doesn't really explain why I (/R) wasn't able to / didn't want to update packages in the second tier library directory *shrug*
ReplyDeletewhat I do on my linux box, is to start R as root, and install any package or update all packages from console. It works like a charm.
ReplyDeleteIs there a way to install methylKit with the latest R version 3?
ReplyDeleteTHANKS IN ADVANCE!
Sometime this week, you will be able to use methylKit with R 3.0
ReplyDelete