You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.#' #' @exportsize<-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
The tools::codoc() function that detects these problems has special handling for finding S3 and S4 methods, and likely also needs special handling of S7 methods to allow them to be documented.
R displays the method usage normally but skips it when checking the documentation. I tried this on R 4.6.1, and it removed the warning. The generic's usage still gets checked.
We could have roxygen2 emit this for S7 methods for now. The downside is that R would also miss incorrect method defaults and missing argument documentation.
For a complete fix, we could propose a \S7method{size}{any} tag in R. That would tell R which method the usage belongs to, so it could compare the documentation with the method's actual arguments. Roxygen2 would emit the tag, and S7 would provide a way for R to find the registered methods.
S7's existing registries seem to have the information we need. The main things to work out would be how to identify methods with multiple dispatch or classes from other packages, and what to do on older R versions. I don't think we need to tackle that now, but it seems like a reasonable direction for a fix.
Activity
t-kalinowski commentedon Sep 30, 2026
I looked into this. A complete fix still seems to need changes in R, though there may be a small workaround we could make in roxygen2.
R already supports
\special{...}inside\usage:R displays the method usage normally but skips it when checking the documentation. I tried this on R 4.6.1, and it removed the warning. The generic's usage still gets checked.
We could have roxygen2 emit this for S7 methods for now. The downside is that R would also miss incorrect method defaults and missing argument documentation.
For a complete fix, we could propose a
\S7method{size}{any}tag in R. That would tell R which method the usage belongs to, so it could compare the documentation with the method's actual arguments. Roxygen2 would emit the tag, and S7 would provide a way for R to find the registered methods.S7's existing registries seem to have the information we need. The main things to work out would be how to identify methods with multiple dispatch or classes from other packages, and what to do on older R versions. I don't think we need to tackle that now, but it seems like a reasonable direction for a fix.
Wrap S7 method usage in `\special{}` (#1928)