[R] Getting Rd pages right for redefined S3 generic

Ken Knoblauch ken.knoblauch at inserm.fr
Fri Dec 18 13:05:08 CET 2009


S Ellison <S.Ellison <at> lgc.co.uk> writes:
> I wanted to define a cbind equivalent for an object that mostly behaves
> like a data frame. base::cbind dispatches to a data frame method if
> _any_ parameter is a data frame, so I defined a new S3 cbind and
> cbind.default to handle dispatch on first object only. Though I confess
> that redefining cbind leaves me a tad nervous, that all works OK so far.
---- clipped ---
> Steve Ellison

Why don't you just define a method for your object class.  It should
dispatch on your method if all of the objects that you give it have
that class.  I did this in the MLDS package in a situation in which
I had a data frame that had additional attributes and I wanted
rbind (in my case) to concatenate the attributes as well as the
actual data frame.  I gave the data frame with these extra attributes
the class of c("mld.df", "data.frame") so that they would still
inherit other data frame methods.  My rbind.mlds.df works fine
with them, and I document it accordingly.

HTH.

Ken

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html




More information about the R-help mailing list