Skip to content
Prev 363619 / 398502 Next

How to test existence of an environment and how to remove it (from within functions)?

On 29/08/2016 4:52 PM, Marius Hofert wrote:
How do you know that's the "right" value?  Just because something is 
cached doesn't mean it's the value corresponding to "x".

You can use some sort of hash to cache values corresponding to 
particular x values, e.g.


hash <- digest::digest(x)
if (exists(hash, envir = .my_environ))
   x.cols <- get(hash, .my_environ)

The memoise package does all of this for you.  You provide the slow 
function aux, then call

aux <- memoise(aux)

and suddenly it will magically remember previously calculated values. 
There are ways to get old values to timeout automatically, etc.

Duncan Murdoch