2013-01-09 62 views
22

我爲一個使用S3類的函數創建了一個roxygen文件。我roxygenize,然後建立和檢查,並得到一個警告:用Roxygen構建R包時的S3方法一致性警告

​​

所以我花時間學習:

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)) 
} 
+0

@hadley感謝您的編輯(即正確使用術語的幫助)。 –

回答

22

我認爲這是因爲一個方法必須具有與泛型相同的參數。因此,將...添加到參數common.list()。就像這樣:

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

同樣,common.default()應該有word.list作爲參數。

+0

我通過把...放在昨天通過,因爲你建議,但我把它放在第一個打破代碼(我現在意識到這只是一個正確的命令的問題)。我非常親密,謝謝你解除我的沮喪。 –

+0

感謝您的提示Andrie。 +1 –

+0

謝謝,@hadley。我刪除了包含錯誤建議的評論。 – Andrie