如何正确记录S4“ [”和“ [< - “使用roxygen的方法?
题
下面我发布了一个迷你示例,我想在其中写文档 “[“
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
})
不隶属于 StackOverflow