[Rd] Error condition in evaluating a promise
Seth Falcon
sfalcon at fhcrc.org
Wed Oct 18 22:30:56 CEST 2006
"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
More information about the R-devel
mailing list