有没有人能给我指一下如何使用Roxygen记录R.oo类/方法的好例子?在R.oo中,类/方法是通过调用setConstructorS3()和setMethodS3()创建的,因此没有要记录的函数。您是否只需创建标准的Roxygen函数文档,然后将其放在一个空语句之上即可?
@usage
标记。MyMethod.ClassName
函数需要一个省略号参数,以保持S3通用/方法的一致性。#' @export MyMethod.ClassName
而是#' @S3method MyMethod ClassName
?一个示例代码:
#' Title. More Info.
#'
#' @usage MyMethod(...)
#' @param this this.
#' @param someParam Param info.
#' @param ... other arguments.
#'
#' @rdname MyMethod
#' @export MyMethod
#' @name MyMethod
NULL
#' @usage \method{MyMethod}{ClassName}(this, someParam, ...)
#' @return MyMethod.ClassName:
#' \code{NULL}
#'
#' @rdname MyMethod
#' @S3method MyMethod ClassName
#' @name MyMethod.ClassName
setMethodS3("MyMethod", "ClassName", appendVarArgs = FALSE,
function(this, someParam, ...) {
NULL
})
经过一些尝试和错误,这是我想出的解决方案。该解决方案确保所有对象都正确导出,R CMD build/check不会出错,没有冗余文档,并且示例将执行。请注意,如果将@export替换为@method/@S3method,则此解决方案将无法正常工作。理论上应该可以,但在我的情况下并没有成功。有人有更好的解决方案吗?
#' Title. More Info.
#'
#' @param someParam Param info.
#'
#' @name MyMethod
#' @export MyMethod
NULL
#' @rdname MyMethod
#' @name MyMethod.ClassName
#' @export MyMethod.ClassName
setMethodS3( "MyMethod" , "ClassName" , appendVarArgs = FALSE ,
function( this , someParam ) { ... } )