Skip to content
Prev 174317 / 398506 Next

classes and methods

mtmorgan at fhcrc.org wrote:
it seems that a generic can dispatch to s3 method on an s4 object, and
to an s4 method on an s3 object, and also that s4 methods capture, or
shadow, s3 methods:

    setClass('foo', representation(x='numeric'))
    setMethod('print', 'foo', function(x, ...) print('foo'))

    s4 = new('foo', x = 0)
    print(s4)
    # "foo"

    s3 = structure(0, class='foo')
    print(s3)
    # "foo"

    print.foo = function(s3) print('bar')
    print(s3)
    # "foo"
    print(s4)
    # "foo"

    removeMethod('print', 'foo')
    print(s3)
    # "bar"
    print(s4)
    # "bar"

is this intended? 

vQ