[R] The lib.loc argument to library().

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Mar 18 22:59:23 CET 2014


On 18/03/2014 21:41, Rolf Turner wrote:
>
>
> I am currently having, uh, difficulties, with the latest version of
> lme4, which I did not have with an elderly version that I was using
> previously.  To check things out I installed the elderly version in a
> directory called "AltRlib", in my home directory.
>
> I kept the latest version (1.1-5) in a directory called "Rlib" in my
> home directory.
>
> I have R_LIBS set equal to "/home/rolf/Rlib" in my environment, so that
> "Rlib" gets searched automatically.
>
> If I start R in my home directory and issue the call
>
>      library(lme4,lib.loc="/home/rolf/AltRlib")
>
> then I get the elderly version as required.
>
> If I start R in a subdirectory, say "/home/Rolf/Foo" and issue
> the *same command*, I get the 1.1-5 version, *NOT* as required.
>
> After some head-scratching I moved the .RData file in "Foo" to
> Save.RData and re-started R.  ***Then*** I got the version of lme4 that
> I wanted.
>
> So I removed all traces of results produced by the 1.1-5 version of lme4
> from Save.RData (saving them elsewhere for safekeeping), moved
> Save.RData back to .RData, re-started R, issued the library command, and
> got the unwanted 1.1-5 version!!!
>
> Can anyone explain WTF is going on?  What is hanging around in .RData
> that causes library() to ignore the "lib.loc" argument?  How can I keep
> library() from ignoring the "lib.loc" argument?

It seems you have already loaded the namespace 'lme4' before you issue 
the library() call.

Try loadedNamespaces() to confirm.

As the help says

      ‘library(package)’ and ‘require(package)’ both load the package
      with name ‘package’ and put it on the search list.  ‘require’ is
      designed for use inside other functions; it returns ‘FALSE’ and
      gives a warning (rather than an error as ‘library()’ does by
      default) if the package does not exist.  Both functions check and
      update the list of currently loaded packages and do not reload a
      package which is already loaded.


>
> Thanks.
>
> cheers,
>
> Rolf Turner
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list