2013-01-09 5 views
22

Ho creato un file di roxygen per una funzione che utilizza S3 una classe. I roxygenize e poi costruire e controllare e ottenere un avvertimento:Avviso di coerenza metodo S3 durante la creazione di pacchetti R con 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. 

Così ho speso tempo a studiare:

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

Ma io non riesco a capire cosa ho fatto di sbagliato nel file qui sotto. La funzione funziona come previsto.
1) perché si verifica l'avviso? 2) come posso farlo andare via?

#' 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 Grazie per la modifica (ad esempio l'aiuto con un utilizzo corretto del termine). –

risposta

22

Penso che questo accada perché un metodo deve avere tutti gli stessi argomenti del generico. Quindi aggiungere ... agli argomenti di common.list(). Come questo:

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

Allo stesso modo, common.default() dovrebbe avere word.list come argomento.

+0

L'ho ottenuto ieri inserendo il ... nel modo suggerito ma l'ho inserito per primo che ha rotto il codice (ora mi rendo conto che era solo questione di ordinare gli argomenti correttamente). Ero così vicino, grazie per aver alleviato la mia frustrazione. –

+0

Grazie per il suggerimento Andrie. +1 –

+0

Grazie, @hadley. Ho cancellato il mio commento che contiene il consiglio sbagliato. – Andrie