2

OS: Mac OS X 10.10.3 R version: 3.2.0 (installed by Homebrew)

I want R to install packages in my home directory instead of the default "R_HOME", so I don't have to reinstall all packages after updating R.

I set the library path by .libPaths('~/Library/R/'). After that, all packages were installed in ~/Library/R. Checking by .libPaths()returned ~/Library/R and the R_HOME.

However, when I quit R (in RStudio or in terminal) and reopen R (in RStudio or terminal), .libPaths() only returned the R_HOME. I have to manually set .libPaths('~/Library/R/') again (the packages are still there).

Why does the library path automatically reset and how could I change it permanently?

Zelong
  • 2,476
  • 7
  • 31
  • 51
  • Did the answer below solve your question? For me I have the same result as in your comment (Apr 18 12:35) and the follow comment did not solve the Problem. I ask, because the answer is marked as "accepted",... – Tonio Liebrand Dec 12 '18 at 15:01

1 Answers1

2

I did something similar. Check your Sys.getenv(). Mine has 57 items. One of them is Sys.getenv()['R_LIBS']. I set it to "/Users/ghuiber/Rlibs" and it is persistent.

Gabi
  • 1,303
  • 16
  • 20
  • 1
    It returns only the R_HOME. I used `Sys.setenv(R_LIBS='~/Library/R')` and `Sys.setenv(R_LIBS_USER='~/Library/R')`. But it reset when I reopened R. – Zelong Apr 18 '15 at 12:38
  • Two notes. First, I just noticed that you have a Homebrew install. The R recipe has a `caveats` function that mentions a custom library folder on line 159 [here](https://github.com/Homebrew/homebrew-science/blob/master/r.rb). Second, instead of changing `.libPaths()` maybe you should append to it, as explained [here](http://stackoverflow.com/questions/15170399/changing-r-default-library-path-using-libpaths-in-rprofile-site-fails-to-work). The same thread discussed alternatives like .Rprofile and `Sys.setenv()`. – Gabi Apr 19 '15 at 20:41