6

Every time R is upgraded, I have to reinstall the packages I use (from sources,so they have to be recompiled for the new version). This is a correct, understandable behavior, so I invoke install.packages - and get an error because the user-writable directory "~/R/%p-library/%v" does not exist yet and all the other directories in .libPaths() are under /usr/ and are not user-writable. This behavior is documented in the referenced pages.

So, after getting the install error, I have to do this:

> dir.create(Sys.getenv("R_LIBS_USER"))
> .libPaths(Sys.getenv("R_LIBS_USER"))
> install.packages(c("igraph","entropy",...))

My question is: how do people deal with this issue?

Create the directory by hand after each upgrade? (but isn't that tedious?)

Add the dir.create call to .Rprofile? (apparently not)

EDIT: I seem to recall that, when I started to use R, this library directory appeared without my action; but I might be wrong...

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278
  • Good question, may be let's try to write a short/complete procedure for upgrading R + packages automatically. – statquant May 03 '13 at 16:37

1 Answers1

3

One thing you could try is specifying an R_LIBS in a .REnviron file in your $HOME$ directory, for instance I am on Windows at work so the first line in my .REnviron is something like R_LIBS="C:\Some\path\library".

Then when you come to update from a major version change you can just use:

update.packages( lib.loc = .libPaths()[1] , checkBuilt = TRUE )

To find out your $HOME$ directory use:

Sys.getenv("HOME")
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
  • Essentially you are making the user library path independent on the R version. Right? – sds May 03 '13 at 17:16
  • @sds exactly, yes. And then the `checkBuilt` makes R consider any packages built under the old version as in need of an update. – Simon O'Hanlon May 03 '13 at 17:16