[R] R-1.4.0 delay()

Luke Tierney luke at stat.umn.edu
Sat Jan 12 14:11:59 CET 2002


On Sat, Jan 12, 2002 at 06:35:03PM +1300, Ray Brownrigg wrote:
> R-1.4.0 seems to have changed the way delay() works, or perhaps it is
> the way library() works that nullifies the advantages of using delay()
> in a package.
> 
> It seems that the process of loading a package evaluates each object
> provided by that package, and so in particular, the delay()ed object is
> evaluated and brought into memory.
> 
> For example generating a test example, where test/R/functions.s is:
> test <- delay({attach(system.file("data/test.rda", package = "test")); test})
> 
> and test/data/test.rda is generated by:
> test <- runif(5000000)
> save(test, file="test/data/test.rda")
> 
> After installing this package (R INSTALL test) then invoking R, we get:
> 
> > library(test)
> 
> Attaching package `test':
> 
> 
> 	The following object(s) are masked _by_
> file:/usr/lib/R/library/test/data/test.rda :
> 
> 	 test 
> 
> > 
> and there is a delay while the .rda file is read into memory.  This also
> happens if the .rda file is external to the package (in /tmp/test.rda
> for example).  Previously (before 1.4.0), the file was not read into
> memory until the object test was referenced the first time.
> 
> I see in library(), there is the code fragment:
> 
>             env <- attach(NULL, name = pkgname)
>             on.exit(do.call("detach", list(name = pkgname)))
>             attr(env, "path") <- file.path(which.lib.loc, package)
>             for (name in ls(loadenv, all = TRUE)) {
>                 val <- get(name, env = loadenv)
>                 rm(list = name, envir = loadenv, inherits = FALSE)
>                 if (typeof(val) == "closure" && identical(environment(val), 
>                   loadenv)) 
>                   environment(val) <- .GlobalEnv
>                 assign(name, val, env = env)
>             }
> 
> which replaces (in 1.3.1):
>             .Internal(lib.fixup(env, .GlobalEnv))
> 
> Could this be the cause?
> 

It's a bug--thanks.  We'll need to put the loop in library() into C
code to make sure things are transferred from the loading to the
installation environment without evaluation.  I'll do that shortly;
should be fixed for 1.4.1.

luke


-- 
Luke Tierney
University of Minnesota                      Phone:           612-625-7843
School of Statistics                         Fax:             612-624-8868
313 Ford Hall, 224 Church St. S.E.           email:      luke at stat.umn.edu
Minneapolis, MN 55455 USA                    WWW:  http://www.stat.umn.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list