From jmc at research.bell-labs.com  Fri May 23 16:37:50 2003
From: jmc at research.bell-labs.com (John Chambers)
Date: Fri May 23 21:38:24 2003
Subject: [Rd] Documenting S4 classes; debugging them
References: <ffoscvkcht69hhsnkhr1t8ci28psb2p10n@4ax.com>
Message-ID: <3ECE788E.5329E293@research.bell-labs.com>

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
documentation.


> 
> 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))
  debug(fNumeric)

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

John

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

-- 
John M. Chambers                  jmc@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


[Rd] Documenting S4 classes; debugging them
John Chambers