Re: [Rd] S3 methods for cbind/rbind

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 27 Sep 2006 - 21:02:07 GMT

Maybe you could use rbind2, which has an S4 generic in the methods package, instead?

# BOD is a data frame built into R
foo <- structure(BOD, class = c("bar", "data.frame")) setOldClass("bar")
setMethod("rbind2", signature(x = "bar", y = "bar"),

	  function(x, y) {
		cat("Hello!\n")
		class(x) <- class(y) <- "data.frame"
		rbind(x, y)
	})

# test
foo <- structure(BOD, class = c("bar", "data.frame")) rbind2(foo, foo)

On 9/27/06, Vincent Goulet <vincent.goulet@act.ulaval.ca> wrote:
> Hum. Then, I need to be more accurate. My object is of class
> c("bar", "data.frame"). So, by virtue of ...
>
> The dispatch algorithm is described in the source file
> ('.../src/main/bind.c') as
>
> 1. For each argument we get the list of possible class
> memberships from the class attribute.
>
> 2. We inspect each class in turn to see if there is an an
> applicable method.
>
> ... rbind(foo) is never sent to rbind.bar(). So I guess my questions stand.
>
> Le Mercredi 27 Septembre 2006 16:16, Gabor Grothendieck a écrit:
> > Actually you can add your own method. See
> >
> > library(zoo)
> > rbind.zoo
> >
> > for an example.
> >
> > On 9/27/06, Vincent Goulet <vincent.goulet@act.ulaval.ca> wrote:
> > > I created a type of object similar to a data frame. In some
> > > circumstances, It needs special methods for "[" and "[<-" and rbind()
> > > (but not cbind()). Then I found this in the cbind()/rbind() man page:
> > >
> > > The method dispatching is _not_ done via 'UseMethod()', but by
> > > C-internal dispatching. Therefore, there is no need for, e.g.,
> > > 'rbind.default'.
> > >
> > > This seems to imply I cannot add my own method. Is there 1) a workaround
> > > to and 2) a rationale for this? (Other than creating a generic Rbind() or
> > > whatever, that is.)
> > >
> > > I'm using S3 methods.
> > >
> > > Thanks in advance!
> > >
> > > --
> > > Vincent Goulet, Associate Professor
> > > École d'actuariat
> > > Université Laval, Québec
> > > Vincent.Goulet_at_act.ulaval.ca http://vgoulet.act.ulaval.ca
> > >
> > > ______________________________________________
> > > R-devel@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Vincent Goulet, Associate Professor
> École d'actuariat
> Université Laval, Québec
> Vincent.Goulet_at_act.ulaval.ca http://vgoulet.act.ulaval.ca
>



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Sep 28 07:06:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 22:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.