Hi all, How can I call the default method of a S3 object defined by a primitive method? i.e. in the following example, how do I call the default [ method instead of the one I defined for the class. new_a <- function(x) structure(x, class = "a") a <- new_a(1:5) "[.a" <- function(x, i, j, ...) { new_a(x[, j, ]) } a[, 5] Thanks, Hadley -- http://had.co.nz/
On Nov 23, 2009, at 16:00 , Hadley Wickham wrote:> Hi all, > > How can I call the default method of a S3 object defined by a > primitive method? i.e. in the following example, how do I call the > default [ method instead of the one I defined for the class. > > new_a <- function(x) structure(x, class = "a") > > a <- new_a(1:5) > > "[.a" <- function(x, i, j, ...) { > new_a(x[, j, ])What about new_a(unclass(x)[, j,]) Cheers, Simon> } > > a[, 5] > > Thanks, > > Hadley > > -- > http://had.co.nz/ > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >
Gabor Grothendieck
2009-Nov-23 23:22 UTC
[Rd] Calling default method for primitive functions
See ?.subset On Mon, Nov 23, 2009 at 4:00 PM, Hadley Wickham <hadley at rice.edu> wrote:> Hi all, > > How can I call the default method of a S3 object defined by a > primitive method? ? i.e. in the following example, how do I call the > default [ method instead of the one I defined for the class. > > new_a <- function(x) structure(x, class = "a") > > a <- new_a(1:5) > > "[.a" <- function(x, i, j, ...) { > ?new_a(x[, j, ]) > } > > a[, 5]
Perfect - thanks! Hadley On Mon, Nov 23, 2009 at 5:22 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> See ?.subset > > On Mon, Nov 23, 2009 at 4:00 PM, Hadley Wickham <hadley at rice.edu> wrote: >> Hi all, >> >> How can I call the default method of a S3 object defined by a >> primitive method? ? i.e. in the following example, how do I call the >> default [ method instead of the one I defined for the class. >> >> new_a <- function(x) structure(x, class = "a") >> >> a <- new_a(1:5) >> >> "[.a" <- function(x, i, j, ...) { >> ?new_a(x[, j, ]) >> } >> >> a[, 5] > >-- http://had.co.nz/