如何记录R6类的S3泛型?
我有一个R6类如何记录R6类的S3泛型?,r,roxygen2,r6,R,Roxygen2,R6,我有一个R6类myclass,我已经为它定义了S3通用作为.matrix。一切正常,但当我运行R CMD check时,我得到了两个注释: 注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 no
myclass
,我已经为它定义了S3通用作为.matrix
。一切正常,但当我运行R CMD check时,我得到了两个注释:
注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类之外):
#“将所有核心转换为R矩阵
#'
#“@param x\code{myclass}
#“@param。。。传递给\code{as.matrix()}的其他参数
#“@返回R矩阵的命名列表。
#“@出口
正如@Mikko建议的那样,我更新了我的roxygen版本(我原来的帖子现在已经相当老了)。在7.1.1中,我不再收到通知。谢谢 我会认为编写一个不返回矩阵的as.matrix
方法是一种糟糕的形式。这无疑会给最终用户带来问题。如果你的方法没有遵循泛型应该做什么的“规则”,那为什么还要使用泛型呢?我无法用roxygen2 7.1.1版重现这一点——升级能解决你的问题吗?
#' 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
)
}