Re: [Rd] Prevent serialization of an environment?
On 13-01-15 7:39 PM, Peter Meilstrup wrote: Within I'm using an environment as a hashtable to cache the results of some repeated computations in a package. The thing is that the contents of the cache will not be valid across R sessions, so I would like to make sure that the cache is cleared if the user saves or restores the workspace (or when a package is prepared for lazy loading, etc.). Is there a way to mark an environment so that its contents do not serialize? Seems like the refhook argument to serialize() could do that. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Prevent serialization of an environment?
On Tue, Jan 15, 2013 at 4:55 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 13-01-15 7:39 PM, Peter Meilstrup wrote: Within I'm using an environment as a hashtable to cache the results of some repeated computations in a package. The thing is that the contents of the cache will not be valid across R sessions, so I would like to make sure that the cache is cleared if the user saves or restores the workspace (or when a package is prepared for lazy loading, etc.). Is there a way to mark an environment so that its contents do not serialize? Seems like the refhook argument to serialize() could do that. Duncan Murdoch But I don't see where e.g. save() allows specifying which refhook to use (or more generally how to ensure that the user always supplies an appropriate refhook.) Or how to tell R CMD BUILD to use a refhook. Unless I misunderstand when refhook comes into play. One example of the kind of thing I'm looking for is in Matlab, where you can have loadobj() or saveobj() methods; if a class has these methods they will be used to mangle objects of that class as they are de/serialized. Peter [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Prevent serialization of an environment?
OK. Based on comments in serialize.c, this sort of thing isn't available(yet). However, I also came to the conclusion that for my purposes (caching functions-of existing R objects) I might implement the cache not with an environment but with the weak-reference facility exposed in the C interfaces. Thanks to those who replied! Peter [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel