Come documentare adeguatamente S4 “[” e “[<-” metodi usando roxygen?
Domanda
Qui di seguito ho postato un mini esempio in cui voglio fare la documentazione di scrittura per
un metodo “[“
per una classe S4. Qualcuno sa come documentare correttamente un metodo per la "["
generico utilizzando roxygen e S4?
Ho ricevuto un avviso quando si controlla il pacchetto dopo la costruzione (vedi sotto).
#' An S4 class that stores a string.
#' @slot a contains a string
#' @export
setClass("testClass",
representation(a="character"))
#' extract method for testClass
#'
#' @docType methods
#' @rdname extract-methods
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
function (x, i, j, ..., drop){
print("void function")
}
)
Estratto dal controllo del pacchetto:
* checking for missing documentation entries ... WARNING
Undocumented S4 methods:
generic '[' and siglist 'testClass'
All user-level objects in a package (including S4 classes and methods)
should have documentation entries.
See the chapter 'Writing R documentation files' in manual 'Writing R Extensions'.
Soluzione
A partire dal roxygen2> 3.0.0, non si ha più bisogno arounds di lavoro e solo bisogno di:
#' Extract parts of testClass.
#'
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
function (x, i, j, ..., drop){
print("void function")
}
)
Altri suggerimenti
Alla fine ho capito più o meno. Almeno ora funziona:
#' An S4 class that stores a string.
#' @slot a contains a string
#' @export
setClass("testClass",
representation(a="character"))
#' extract parts of testClass
#'
#' @name [
#' @aliases [,testClass-method
#' @docType methods
#' @rdname extract-methods
#'
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
function (x, i, j, ..., drop){
print("void function")
}
)
Per quello che vale, nel caso di una funzione di sostituzione, si vorrà qualcosa di simile al seguente:
#' An S4 class that stores a list.
#' @export
setClass("testClass",
representation(a="list"))
#' extract parts of testClass
#'
#' @name [
#' @aliases [,testClass-method
#' @docType methods
#' @rdname extract-methods
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
function (x, i, j, ..., drop) {
x@a[i]
}
)
#' replace names of testClass
#'
#' @name [
#' @aliases [<-,testClass-method
#' @docType methods
#' @rdname extract-methods
setReplaceMethod("names", signature(x = "testClass", value = "ANY"), definition = function (x, value) {
names(x@a) <- value
x
})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow