How to properly document S4 "[" and “[<-“ methods using roxygen?

r, r-s4, roxygen

Solution

As of roxygen2 >3.0.0, you no longer need work arounds and only need:

#' Extract parts of testClass.
#'
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
  function (x, i, j, ..., drop){
    print("void function")
  }
)

Problem

Below I posted a mini example in which I want do write documentation for an `“[“` method for a S4 class. Does someone know how to properly document a method for the generic `"["` using roxygen and S4? I get a warning when checking the package after building (see below). ``` #' An S4 class that stores a string. #' @slot a contains a string #' @export setClass("testClass", representation(a="character")) #' extract method for testClass #' #' @docType methods #' @rdname extract-methods setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"), function (x, i, j, ..., drop){ print("void function") } ) ``` Excerpt from package check: ``` * checking for missing documentation entries ... WARNING Undocumented S4 methods: generic '[' and siglist 'testClass' All user-level objects in a package (including S4 classes and methods) should have documentation entries. See the chapter 'Writing R documentation files' in manual 'Writing R Extensions'. ```

Original source