gpt4 book ai didi

r - 使用Roxygen构建R包时的S3方法一致性警告

转载 作者:行者123 更新时间:2023-12-03 08:58:01 25 4
gpt4 key购买 nike

我为使用S3类的函数创建了一个roxygen文件。我进行充氧,然后构建并检查并得到警告:

* checking S3 generic/method consistency ... WARNING
common:
function(word.list, ...)
common.list:
function(word.list, overlap, equal.or)

See section 'Generic functions and methods' of the 'Writing R
Extensions' manual.

所以我花时间研究:

http://cran.r-project.org/doc/manuals/R-exts.html#Generic-functions-and-methods
https://github.com/hadley/devtools/wiki/S3

但是我无法弄清楚下面文件中做错了什么。该功能按预期工作。
1)为什么会发生警告?
2)我怎样才能使它消失?
#' Find Common Words Between Groups
#'
#' Find common words between grouping variables (e.g. people).
#'
#' @param word.list A list of names chacter vectors.
#' @param overlap Minimum/exact amount of overlap.
#' @param equal.or A character vector of c(\code{"equal"}, \code{"greater"},
#' \code{"more"}, \code{"less"}).
#' @param \dots In liu of word.list the user may input n number of character
#' vectors.
#' @rdname common
#' @return Returns a dataframe of all words that match the criteria set by
#' \code{overlap} and \code{equal.or}.
#' @export
#' @examples
#' a <- c("a", "cat", "dog", "the", "the")
#' b <- c("corn", "a", "chicken", "the")
#' d <- c("house", "feed", "a", "the", "chicken")
#' common(a, b, d, overlap=2)
#' common(a, b, d, overlap=3)
#'
#' r <- list(a, b, d)
#' common(r)
#' common(r, overlap=2)
common <-
function(word.list, ...){
UseMethod("common")
}

#' @return \code{NULL}
#'
#' @rdname common
#' @method common list
#' @S3method common list
common.list <-
function(word.list, overlap = "all", equal.or = "more"){
if(overlap=="all") {
OL <- length(word.list)
} else {
OL <- overlap
}
LIS <- sapply(word.list, unique)
DF <- as.data.frame(table(unlist(LIS)), stringsAsFactors = FALSE)
names(DF) <- c("word", "freq")
DF <- DF[order(-DF$freq, DF$word), ]
DF <- switch(equal.or,
equal = DF[DF$freq == OL, ],
greater = DF[DF$freq > (OL - 1), ],
more = DF[DF$freq > (OL - 1), ],
less = DF[DF$freq < (OL + 1), ])
rownames(DF) <- 1:nrow(DF)
return(DF)
}

#' @return \code{NULL}
#'
#' @rdname common
#' @method common default
#' @S3method common default
common.default <-
function(..., overlap = "all", equal.or = "equal"){
LIS <- list(...)
return(common.list(LIS, overlap, equal.or))
}

最佳答案

我认为发生这种情况是因为方法必须具有与泛型相同的所有参数。因此,将...添加到common.list()的参数中。像这样:

common.list <- function(word.list, overlap = "all", equal.or = "more", ...)

同样, common.default()应该以 word.list作为参数。

关于r - 使用Roxygen构建R包时的S3方法一致性警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14237018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com