【发布时间】:2020-04-21 19:19:35
【问题描述】:
我有一个 R6 类 myclass,我已经为它定义了 S3 泛型 as.matrix。一切正常,但是当我运行 R CMD 检查时,我得到了 2 个注释:
注1:
S3 methods shown with full name in documentation object 'as.matrix.myclass':
'as.matrix.myclass'
The \usage entries for S3 methods should use the \method markup and not
their full name.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
注2:
Found the following apparent S3 methods exported but not registered:
as.matrix.myclass
See section 'Registering S3 methods' in the 'Writing R Extensions'
manual.
这是我如何定义和记录我的 S3 泛型(这在 R6 类之外):
#' Converts all cores to R matrices
#'
#' @param x \code{myclass}
#' @param ... other arguments passed to \code{as.matrix()}
#' @return A named list of R matrices.
#' @export
as.matrix.myclass <- function(x, ...) {
sapply(
x$cores,
function(x, ...) as.matrix(x, ...),
USE.NAMES = TRUE, simplify = FALSE
)
}
我正在使用支持 R6 文档的更新版本的 roxygen,但我找不到任何关于如何摆脱这些注释的信息。谢谢!
【问题讨论】:
-
我会认为编写不返回矩阵的
as.matrix方法是一种糟糕的形式。这肯定会给最终用户带来问题。如果你的方法不遵守泛型应该做的“规则”,为什么还要使用泛型? -
我无法使用 roxygen2 版本 7.1.1 重现此问题——升级能否解决您的问题?