我在尝试检查包时收到以下提示: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{https://stackoverflow.com/questions/18142117/how-to-replace-nan-value-with-zero-in-a-huge-data-frame/18143097#18143097}
#'
#' @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)
请注意,运行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.
似乎有一种解决方案是将函数重命名为使用下划线分隔符(_
(而不是点分隔符(.
((如何在不引用S3方法的情况下注册方法(。但是,如果可能的话,我想保留点分隔符(.
(,这样我就可以使用向量和数据帧的is.nan()
函数(通过方法分派(。如何导出此函数并删除注释?
FYI这里是解决问题后的固定文档(基于有用的答案和评论(——这不再引起注意或警告:
#' @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{https://stackoverflow.com/questions/18142117/how-to-replace-nan-value-with-zero-in-a-huge-data-frame/18143097#18143097}
#'
#' @method is.nan data.frame
#'
#' @export
is.nan.data.frame <- function(x) do.call(cbind, lapply(x, is.nan))
我对Roxygen2
不是很了解,但您似乎已经将is.nan.data.frame
声明为类data.frame
的is.nan
方法。既然这样做了,那么在帮助页面示例中应该将其称为is.nan(df)
。
如果您不希望它是方法,只希望它是名称中使用句点的常规函数,那么就不应该有@method is.nan data.frame
。但你表示你确实希望它成为一种方法。
编辑添加:只是为了总结你的评论,以下修复程序消除了所有错误:
- 在不命名函数的情况下自行使用@export(如@KonradRudolph所建议的(
- 删除@usage行
- 在示例中使用
is.nan(df)
(正如我所建议的(