1

I have a custom class, called "FOO", and would like to set the "length" method for that class. Here is a template:

#' Returns the length of the FOO object
#'
#' @name length
#' @param x a FOO object
#' @aliases XXX
#' @rdname YYY
#' @docType methods
setMethod("length", "tmod",
  function(x) {
    nrow(x$BLAH)
  })

The method itself works correctly.

bar <- list(BLAH=1:10)
bar <- as(bar, "FOO")
length(bar)

...returns 10.

My question: what should be entered instead of "XXX" and "YYY"? The entry on documenting S4 methods and classes in "Writing R extensions" is a bit on the short side, to put it mildly. Documentation of roxygen2 is using made up examples. But what should I do if I want to use a generic which was not defined by me?

Note that the difference between, say, this question is that I am specifically asking about defining the "length" method which corresponds to a function from the base package. This is quite different from the "show" for which a "show-methods" manual page already exists.

John Paul
  • 12,196
  • 6
  • 55
  • 75
January
  • 16,320
  • 6
  • 52
  • 74
  • Possible duplicate of https://stackoverflow.com/questions/7356120/how-to-properly-document-s4-methods-using-roxygen2?rq=1 – JDL Mar 23 '18 at 14:07
  • Possible duplicate of [How to properly document S4 methods using roxygen2](https://stackoverflow.com/questions/7356120/how-to-properly-document-s4-methods-using-roxygen2) – JDL Mar 23 '18 at 14:08
  • No, this is not a duplicate. I am specifically asking about documenting a method which coincides with an existing *function*. This is not covered in that questions. – January Mar 23 '18 at 17:40

0 Answers0