Frage

Im Folgenden gab ich ein Mini-Beispiel, in dem ich Dokumentation schreiben will ein “[“ Verfahren für eine Klasse S4. Hat jemand wissen, wie man richtig ein Verfahren für den generischen "[" dokumentiert mit roxygen und S4?
Ich erhalte eine Warnung, wenn das Paket Überprüfung nach dem Bau (siehe unten).

#' 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")
         }
)

Auszug aus Paketprüfung:

* 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'.
War es hilfreich?

Lösung

Ab roxygen2> 3.0.0 Sie nicht mehr benötigen Arbeit arounds und brauchen nur:

#' Extract parts of testClass.
#'
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
  function (x, i, j, ..., drop){
    print("void function")
  }
)

Andere Tipps

ich es endlich dachte mehr oder weniger aus. Zumindest funktioniert es jetzt:

#' 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")
    }
)

Für das, was es wert ist, im Fall einer Ersatzfunktion, Sie so etwas wie die folgenden wollen werden:

#' 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
})
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top