首页 > 解决方案 > 如何为 R6 类记录 S3 泛型?

问题描述

我有一个 R6 类myclass,我已经as.matrix为它定义了 S3 泛型。一切正常,但是当我运行 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,但我找不到有关如何摆脱这些注释的任何信息。谢谢!

标签: rroxygen2r6

解决方案


正如@Mikko 建议的那样,我更新了我的 roxygen 版本(我原来的帖子现在已经相当老了)。在 7.1.1 中,我不再收到该注释。谢谢!


推荐阅读