Just like other R objects, S4 class and method definitions are documented with *.Rd files stored in the man subdirectory of the package source.
Besides reading the relevant section of R-exts, I'd suggest downloading and looking at the source of a well-written S4-based package with which you're familiar. (For me that would likely be sp, lme4 or Matrix.)
Finally, the methods package includes two nifty utility functions, promptClass()
and promptMethods()
that will fill out a skeleton *.Rd file for any S4 class or method defined in the current R session.
As an example that uses R objects defined in the sp package, you could do this:
library(sp) ## for some example S4 classes and methods
promptClass("SpatialPolygons")
# A shell of class documentation has been written to the file
# ‘SpatialPolygons-class.Rd’.
promptMethods("bbox")
# A shell of methods documentation has been written to the file
# ‘bbox-methods.Rd’.
And then take a look at the files SpatialPolygons-class.Rd
and bbox-methods.Rd
to see how much work those functions will save you!
Edit: After a quick reread of your question, I see you were also asking about how to include the methods and classes themselves. My advice for that's basically the same: read the manual and "use the source" (making sure to also look at how exportClasses()
and exportMethods()
directives in the NAMESPACE
file are used to export S4 objects.)