[R] Getting Rd pages right for redefined S3 generic

Duncan Murdoch murdoch at stats.uwo.ca
Fri Dec 18 12:49:02 CET 2009


On 17/12/2009 11:08 PM, S Ellison wrote:
> I'm writing a package, and would appreciate advice on controlling the
> help documentation cross-references for a redefined generic.
> 
> 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.
> 
> However, R cmd tells me (rightly) that I haven't documented the generic
> and new default. But I don't want to; I want ?cbind to point to the base
> package help pages, not to mine.

But then the documentation will be incorrect, since it mentions the 
non-standard handling of dataframes, which you've done away with.

> Assuming that's not unwise (?), what do I have to do to tell R cmd that
> it should not look for Rd docs for cbind and cbind.default in my package
> whilst still having my generic handle dispatch correctly?
> 
> It looks like one answer _might_ be not to export my redefined cbind  -
> but will a local generic still work properly if it's not exported?

I would say that what you've done is unwise.  I would rename the 
function to avoid future confusion, especially if you decide to export 
it.  Even if it's for internal use only, won't you want a reminder in 2 
years time that cbind(a,b) doesn't mean what the documentation says it 
means?

Duncan Murdoch




More information about the R-help mailing list