[Rd] Documenting S4 classes; debugging them

John Chambers jmc at research.bell-labs.com
Fri May 23 16:37:50 MEST 2003

Duncan Murdoch wrote:
> 1.  I'm putting together my first package that uses S4 classes and
> objects.  I'd like to document them, but I'm not sure what the
> documentation should look like, and package.skeleton doesn't produce
> any at all for the classes or methods.

Hmm, sounds as if it should.

Meanwhile, promptClass and promptMethods generate skeleton

> Are there any good examples to follow?

The bioconductor packages (e.g, Biobase) have some examples.

> 2.  How do I do the equivalent of debug(foo), when foo is an anonymous
> function being used as a method?

The S4-style trace() function allows you to insert debugging functions
(or any expressions) into functions; it has a `signature' argument that
causes the debugging to be inserted into the method with the
corresponding signature.

Usually either `browser' or `recover' are suitable functions to insert.

My canonical piece of debugging code is along the lines of:

   trace("f", signature = "numeric", browser, exit = browser)

If you are really attached to debug(), you can insert an extra level of
function call; i.e., instead of:

  fNumeric <- function(x)x+1
  setMethod("f", "numeric", fNumeric)

and then the call to trace, do
  setMethod("f", "numeric", function(x)fNumeric(x))

But trace() is more flexible, though requiring a bit more typing.


> Duncan Murdoch
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel

John M. Chambers                  jmc at bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc

More information about the R-devel mailing list