[R] "problem" with delay()

Thomas Lumley thomas at biostat.washington.edu
Fri Jun 30 18:44:16 CEST 2000


On Fri, 30 Jun 2000, Ray Brownrigg wrote:

> I have been using delay()  quite successfully to 'load on reference'
> some large data files (earthquake catalogues).  One minor difficulty I
> have not been able to overcome is that upon first reference, the data
> set is loaded into memory as expected, but also remains as a permanent
> object in the user's environment, instead of appearing to be only in
> the library from which it was loaded. 

Your problem is that data() does load the object into the global
environment. To put data in another environment you need to use load(),
source(), read.table() &c, explicitly.

It looks as though you want something like
test.x<-delay({
 pkgenv<-pos.to.env(match("package:mypackage",search()))
 load(system.file("data","data.rda",pkg="mypackage"),envir=pkgenv)
 return(get("test.x",envir=pkgenv))
})

where "mypackage" is the package name, "data.rda" is the data file and
"test.x" is the variable name

Alternatively, if your data are in the R save() format and you are using
1.1.0 or newer you can delay an attach command

test.x<-delay({attach("data.rda")})

or if the file is in the data subdirectory of "mypackage"

test.x<-delay({attach(system.file("data","data.rda",pkg="mypackage"))})

This loads the file into a new environment in the search path, so it won't
be saved on exit.

	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle


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