Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have to create the directory "~/R/%p-library/%v" by hand on each R upgrade?

Tags:

r

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...

like image 545
sds Avatar asked May 03 '13 16:05

sds


1 Answers

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")
like image 60
Simon O'Hanlon Avatar answered Sep 28 '22 05:09

Simon O'Hanlon