R 包文档:"Found the following apparent S3 methods exported but not registered"

R package documentation: "Found the following apparent S3 methods exported but not registered"

我在检查包裹时收到以下提示:Found the following apparent S3 methods exported but not registered: is.nan.data.frame

这是我与 roxygen2 一起用于创建包文档的文档:

#' @title
#' NaN (Not a Number).
#'
#' @description
#' Check whether a value is "Not A Number" (\code{NaN}) in a dataframe.
#'
#' @details
#' [INSERT].
#'
#' @param x Dataframe.
#'
#' @return \code{TRUE} or \code{FALSE}, indicating whether values in a dataframe
#' are Not a Number (\code{NA}).
#'
#' @family dataEvaluations
#'
#' @usage is.nan.data.frame(x)
#'
#' @examples
#' # Prepare Data
#' df <- data.frame(item1 = rnorm(1000), item2 = rnorm(1000), item3 = rnorm(1000))
#' df[sample(1:nrow(df), size = 100), c("item1","item2","item3")] <- NaN
#'
#' # Calculate Missingness-Adjusted Row Sum
#' is.nan.data.frame(df)
#'
#' @seealso
#' \url{
#'
#' @method is.nan data.frame
#'
#' @export is.nan.data.frame
is.nan.data.frame <- function(x) do.call(cbind, lapply(x, is.nan))

这是我的 NAMESPACE 文件中的相关行:

export(is.nan.data.frame)

请注意,我在 运行ning roxygen2 时收到以下警告:

> library("roxygen2")
> roxygenise()
i Loading petersenlab
Writing NAMESPACE
Writing NAMESPACE
Warning message:
In setup_ns_exports(path, export_all, export_imports) :
  Objects listed as exports, but not present in namespace: data.frame, is.nan

这是我运行包检查时的相关输出:

N  checking S3 generic/method consistency (3.3s)
   Found the following apparent S3 methods exported but not registered:
     is.nan.data.frame
   See section 'Registering S3 methods' in the 'Writing R Extensions'
   manual.
...
   S3 methods shown with full name in documentation object 'is.nan.data.frame':
     'is.nan.data.frame'
   
   The \usage entries for S3 methods should use the \method markup and not
   their full name.

似乎解决此问题的一种方法是重命名函数以使用下划线分隔符 (_) 而不是点分隔符 (.) (). However, I'd like to keep the dot separators (.) if possible so that I can use the is.nan() function with vectors and dataframes (via method dispatch)。我怎样才能导出这个函数并去掉注释?


仅供参考,这是解决问题后的固定文档(基于有用的答案和评论)——这不再引发注释或警告:

#' @title
#' NaN (Not a Number).
#'
#' @description
#' Check whether a value is "Not A Number" (\code{NaN}) in a dataframe.
#'
#' @details
#' [INSERT].
#'
#' @param x Dataframe.
#'
#' @return \code{TRUE} or \code{FALSE}, indicating whether values in a dataframe
#' are Not a Number (\code{NA}).
#'
#' @family dataEvaluations
#'
#' @examples
#' # Prepare Data
#' df <- data.frame(item1 = rnorm(1000), item2 = rnorm(1000), item3 = rnorm(1000))
#' df[sample(1:nrow(df), size = 100), c("item1","item2","item3")] <- NaN
#'
#' # Calculate Missingness-Adjusted Row Sum
#' is.nan(df)
#'
#' @seealso
#' \url{
#'
#' @method is.nan data.frame
#'
#' @export
is.nan.data.frame <- function(x) do.call(cbind, lapply(x, is.nan))

我不太了解 Roxygen2,但您似乎已将 is.nan.data.frame 声明为 class data.frameis.nan 方法.既然你这样做了,你应该在帮助页面示例中将其称为 is.nan(df)

如果你不希望它成为方法,而只是希望它成为名称中使用点的常规函数​​,那么你不应该 @method is.nan data.frame。但是您表示确实希望它成为一种方法。

编辑添加:为了总结您的评论,以下修复消除了所有错误:

  • 单独使用@export 而不命名函数(如@KonradRudolph 所建议)
  • 删除@usage 行
  • 在示例中使用 is.nan(df)(按照我的建议)