[R] Singleton pattern

j verzani jverzani at gmail.com
Fri Mar 16 17:09:50 CET 2012

David Cassany <david.cassany <at> transmuralbiotech.com> writes:

> Hi all,
> I know it may not have much sense thinking about a Singleton Pattern in an
> R application which doesn't use any OOP facilities, however I'm curious to
> know if anybody faced the same issue. I've been googling but using
> "singleton pattern" as a key word leads to typical OOP languages like Java
> or C++ among others.

While it isn't too hard to implement the Singleton pattern using reference 
classes, I would think for what you want to do the memoise package can 
be used. Create a wrapper function to return the objects and the cached
value will be returned each time.

> So my problem is that I'd like to ensure some very big objects aren't
> copied again and again in some other variables. In the worst case I'll
> check all code by myself to ensure it but in this case the application
> won't force programmers to take it in consideration which is what I am
> really looking for.
> Any advice will be highly appreciated :P
> Thanks!

More information about the R-help mailing list