Skip to content

Documentation for S7 methods with additional arguments to the generic #1872

@mitchelloharawild

Description

@mitchelloharawild

Documenting S7 methods with additional non-generic arguments triggers CRAN check warnings since the methods themselves are invisible to the checks. I don't see an elegant fix for this without R changes that make the CRAN checks aware of S7 method arguments. An inelegant solution could be to separately document the S7 method usage and arguments in an Rd section (e.g. Methods) which is outside the attention of CRAN checks.

MRE:

#' Size of an object
#'
#' @description
#' `size()` determines the size of an object.
#'
#' # Methods
#' `size()` is an S7 generic with methods available for the following
#' classes:
#'
#' `r doclisting::methods_list("size")`
#'
#' @param x An object.
#' @param ... Not used.
#' @returns A single number.
#' 
#' @export
size <- S7::new_generic("size", "x")

#' @rdname size
#' @param na.rm If TRUE, missing values are not included in the calculation of the size of an object.
S7::method(size, S7::class_any) <- function(x, ..., na.rm = FALSE) {
  if (na.rm) x <- x[!is.na(x)]
  length(x)
}

Produces the CRAN check warning:

❯ checking for code/documentation mismatches ... WARNING
  Codoc mismatches from Rd file 'size.Rd':
  size
    Code: function(x, ...)
    Docs: function(x, ..., na.rm = FALSE)
    Argument names in docs not in code:
      na.rm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions