R: Documenting ellipsis arguments with roxygen2 in S4 generic

I have a number of functions that have associated methods with different arguments that I want to combine into a common one. Is there a standard method for documenting arguments passed through ellipsis with the generic S4 method? Ideally, I would like to concatenate the arguments passed to the various methods for maximum readability.

This is how I am currently trying to do it based on what I read in Documenting Multiple Functions in One File :

#' A class
#' @export
setClass("A", slots = c(a = 'numeric'))

#' B class
#' @export
setClass("B", slots = c(b = 'numeric'))

#' foo generic
#'
#' foo generic description
#'
#' @param object The object
#' @param x shared argument
#' @param ... other arguments passed to methods
#' @export
setGeneric("foo", function(object, x, ...) standardGeneric("foo"))

#' foo method A
#'
#' foo method A description
#'
#' @param y method A argument
#' @rdname foo
#' @export
setMethod("foo", "A", function(object, x, y = 1) {NULL})

#' foo method B
#'
#' foo method B description
#'
#' @param z method B argument
#' @rdname foo
#' @export
setMethod("foo", "B", function(object, x, z = 2) {NULL})

      

The result is pretty close to what I want, but all the extra arguments are just grouped after the ellipses.

Usage:

     foo(object, x, ...)

     ## S4 method for signature 'A'
     foo(object, x, y = 1)

     ## S4 method for signature 'B'
     foo(object, x, z = 2)

Arguments:

  object: The object

       x: shared argument

     ...: other arguments passed to methods

       y: method A argument

       z: method B argument

      

Is there a way to explicitly mark parameters as belonging to a specific method / class (not just writing it down in the description), similar to the usage section, or should I use a completely different structure?

+3


source to share





All Articles