【问题标题】:How do document an S3 generic for an R6 class?如何为 R6 类记录 S3 泛型?
【发布时间】: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 重现此问题——升级能否解决您的问题?

标签: r roxygen2 r6


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多