[Rd] Reference Classes: Accessing methods via [[...]], bug?
geoffjentry at hexdump.org
Tue May 3 20:55:47 CEST 2011
On Sun, 1 May 2011, Martin Morgan wrote:
> On 05/01/2011 03:09 PM, John Chambers wrote:
>> It would be interesting to get some experience and opinions on whether
>> this is a good idea or not. It breaks encapsulation, in that the
>> behavior of the class can no longer be inferred from the class
>> definition alone. On the other hand, it is convenient and relates to
>> "operator overloading" in some other languages.
> I have written 'show' methods for reference classes (is there another way to
> pretty-print them?) and S4 methods that dispatch to reference methods (in
> particular, yield(x) on connection-like classes dispatching to x$yield()).
Most of my S4 method usage with reference classes has been the 'show'
methods for the same reason that Martin states - I was unable to find
another mechanism of pretty printing, and wanted something along those
lines for situations such as a list of objects and how that gets rendered
on the screen.
I've also made use of S4 methods for reference classes to help maintain
backwards compatibility for cases where I've changed the underlying
implementation from S4 to using reference classes - in those cases the
ability to use S4 methods was handy but not strictly necessary.
More information about the R-devel