Sorry, embarrassing stupid error: of course '.libPaths(path.r.lib)' will 
do the trick for me.

Regards,
Janko

-------- Original Message --------
Subject: 	Bug: argument 'lib.loc' not passed on appropriately in 
'library()'?
Date: 	Thu, 18 Aug 2011 19:31:02 +0200
From: 	Janko Thyson <janko.thyson.rstuff@googlemail.com>
To: 	org, r-devel@r-project. <r-devel@r-project.org>



Dear list,

I'm experimenting with setting up custom 'lib' and 'destdir' directories
for my R packages. It seems to me that 'library()' does handle a custom
'lib.loc' argument the way it should for an arbitrary package but NOT
for its dependencies on other packages. The latter are looked for in the
default lib path (~/R/R-2.x.x/library) and NOT in the custom lib path.

Below is a little code example illustrating the error I'm getting. It'd
be great if someone could validate this.

Thanks a lot for any comments,
Janko

### CODE EXAMPLE ###

# Package that I'm sure of that it's not already installed and has
dependencies
pkg<- "rworldmap"

# Making sure that dependencies are not available in the default library
remove.packages("sp")
remove.packages("maptools")
remove.packages("foreign")
remove.packages("lattice")

# Setting custom lib and destdir
path.r.lib<- "C:/temp/R/library"
dir.create(path.r.lib, recursive=TRUE, showWarning=FALSE)
path.r.destdir<- "C:/temp/R/destdir"
dir.create(path.r.destdir, recursive=TRUE, showWarning=FALSE)

# Core processing
try.res<- try(
     eval(substitute(
         library(PKG, lib.loc=path.r.lib, verbose=FALSE),
         list(PKG=pkg)
     )),
     silent=TRUE
)
if(inherits(try.res, "try-error")){
     msg<- c(
         paste("Required package '", pkg, "' not available locally",
sep=""),
         paste("Looking for package '", pkg, "' in remote repository",
sep="")
     )
     cat(msg, sep="\n")
     install.packages(
         pkg,
         repos=getOption("repos"),
         lib=path.r.lib,
         destdir=path.r.destdir,
         dependencies="Depends"
     )
     eval(substitute(
         library(PKG, lib.loc=path.r.lib, verbose=FALSE),
         list(PKG=pkg)
     ))
# Here's where the error occurs. Seems to me that 'lib.loc' is not really
# passed on appropriately within 'library()', but instead the default
lib path
# is used to look for dependencies.
}




	[[alternative HTML version deleted]]

