3

I have had this problem once before, and I can’t figure out the best way to fix it.

I am upgrading r from v3.1.2_1 to v3.1.3 to using brew upgrade r. But when I do that I lose all the libraries that I installed under v3.1.2_1. I have to install all the libraries from scratch.

The problem seems to be that brew creates two independent directory structures for two different versions of R under /usr/local/Cellar/r. Is there a way to install R by telling it to use the existing libraries that have been installed?

I could just copy over the files from one version to another, but I am afraid of breaking something.

vyom
  • 249
  • 3
  • 10
  • Did you even change your package directory? I believe the default User package directory is "/Users/username/Library/R/3.1/library" for 3.1.x. Since the update was a small update, it shouldn't change the user directory. If the user package directory does not exist, try to create one. And check in R: `.libPaths()`. – Randy Lai Apr 06 '15 at 22:05
  • I did not change the package directory. doing `.libpaths()` gives: `"/usr/local/Cellar/r/3.1.2_1/R.framework/Versions/3.1/Resources/library"` – vyom Apr 07 '15 at 05:48
  • Possible duplicate of [Everytime I upgrade R using homebrew I need to install most packages again](https://stackoverflow.com/questions/27866834/everytime-i-upgrade-r-using-homebrew-i-need-to-install-most-packages-again) – slhck Jul 12 '17 at 13:38

1 Answers1

1

You can tell R where to store libraries:

R_LIBS=~/Rlibs

New version of R will look for libraries in this folder. But you will still have to update libraries:

update.packages()

Details are outlined in this post. As a side matter, have a look at the point 2.8 in R FAQ, this one is for Windows but the point is fairly generic. You may be willing to keep old installations the way they are or install new libraries.

Konrad
  • 17,740
  • 16
  • 106
  • 167
  • Thank you. The link to the R FAQ helped. I copied over my old packages to the new installation following the instructions there. I appreciate the point about using a custom library path in R_LIBS, but if I am not wrong that will only help with packages that are installed from that point. I am asking about packages that I have already installed (there are a lot of them) which I want to use with the new version of R. – vyom Apr 07 '15 at 06:15
  • @vyom On principle, the safest way to do it is install your packages anew into designated directory and then do the updates. If you insist on moving your packages, have a look at [this discussion](http://superuser.com/questions/474511/move-installed-r-library-to-other-directory), you can attempt to move your packages from one directory to another but I wouldn't recommend that. To save time [you could install packages via some neat loop](http://stackoverflow.com/questions/8175912/load-multiple-packages-at-once). – Konrad Apr 07 '15 at 10:23