[R] R-1.4.0 delay()
Ray Brownrigg
Ray.Brownrigg at mcs.vuw.ac.nz
Sat Jan 12 06:35:03 CET 2002
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?
I am reluctant to flag this as a bug, since delay() is documented
to be experimental.
Is there perhaps a workaround which will allow a package to install a
delayed reference?
I seem to remember that there may be another way of doing this
(reported by Duncan T-L?), which I will need to delve into if there is
no workaround.
Ray Brownrigg
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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