s4 ["および“ [< - "roxygenを使用したメソッドを適切に文書化する方法?

StackOverflow https://stackoverflow.com/questions/4396768

  •  10-10-2019
  •  | 
  •  

質問

以下に、私がしたいミニの例を投稿しました。 “[“ S4クラスの方法。誰かがジェネリックの方法を適切に文書化する方法を知っていますか "[" RoxygenとS4を使用していますか?
建設後にパッケージをチェックするときに警告が表示されます(以下を参照)。

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

パッケージチェックからの抜粋:

* 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'.
役に立ちましたか?

解決

roxygen2> 3.0.0の時点で、あなたはもう仕事をする必要はなく、次のことだけが必要です。

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

他のヒント

私はついに多かれ少なかれそれを理解しました。少なくとも今は機能します:

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

それが価値があることについては、交換機能の場合、次のようなものが必要です。

#' 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
})
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top