From sfalcon at fhcrc.org  Wed Oct 18 22:30:56 2006
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Wed, 18 Oct 2006 13:30:56 -0700
Subject: [Rd] Error condition in evaluating a promise
In-Reply-To: <4536618D.9070409@gmail.com> (Roger D. Peng's message of "Wed,
	18 Oct 2006 13:17:01 -0400")
References: <0359A469-1F7D-4CEF-A408-CCB185D5F90E@r-project.org>
	<6phvemixy1u.fsf@gopher4.fhcrc.org>
	<6phvemiuw3r.fsf@gopher4.fhcrc.org>
	<9AE19AAE-9CAD-4697-82DC-07724445114C@r-project.org>
	<m2d58psl5d.fsf@ziti.local>
	<5EB2115D-9911-4268-85FA-9AB03F0D9009@r-project.org>
	<45365539.9050106@fhcrc.org> <4536618D.9070409@gmail.com>
Message-ID: <m28xjdicxr.fsf@ziti.local>

"Roger D. Peng" <rdpeng at gmail.com> writes:

> I've encountered a (I think) related problem when using promises to load 
> relatively large datasets.  For example something like
>
> delayedAssign("x", getBigDataset())
>
> runs into the same problem if you hit Ctrl-C while 'x' is being evaluated for 
> the first time.  Afterwards, there's no way to retrieve the dataset associated 
> with 'x'.
>
> Active bindings work in this case, but the problem is that I usually only want 
> to load a large dataset once.

You can do that with active bindings.  Have the function look in an
environment for the data.  If found, return it.  If not, load it into
the env and then return it.

We are using this approach in the BSGenome package in BioC (look there
for an example if you want) and it provides behavior very similar to
lazy data, but more manageable in a number of ways.

+ seth




[Rd] Error condition in evaluating a promise
Seth Falcon