sso*_*len 5 r ellipsis s4 roxygen2
我有许多函数,它们具有不同参数的相关方法,我想在泛型中一起记录.有没有一种标准方法可以通过S4泛型将通过省略号传递的参数记录到不同的方法中?理想情况下,我想将传递给不同方法的参数组合在一起以获得最大可读性.
以下是我目前正在尝试根据我在同一文件中记录多个函数时所读到的内容:
#' A class
#' @export
setClass("A", slots = c(a = 'numeric'))
#' B class
#' @export
setClass("B", slots = c(b = 'numeric'))
#' foo generic
#'
#' foo generic description
#'
#' @param object The object
#' @param x shared argument
#' @param ... other arguments passed to methods
#' @export
setGeneric("foo", function(object, x, ...) standardGeneric("foo"))
#' foo method A
#'
#' foo method A description
#'
#' @param y method A argument
#' @rdname foo
#' @export
setMethod("foo", "A", function(object, x, y = 1) {NULL})
#' foo method B
#'
#' foo method B description
#'
#' @param z method B argument
#' @rdname foo
#' @export
setMethod("foo", "B", function(object, x, z = 2) {NULL})
Run Code Online (Sandbox Code Playgroud)
结果非常接近我想要的结果,但所有额外的参数只是在省略号之后简单地集中在一起.
Usage:
foo(object, x, ...)
## S4 method for signature 'A'
foo(object, x, y = 1)
## S4 method for signature 'B'
foo(object, x, z = 2)
Arguments:
object: The object
x: shared argument
...: other arguments passed to methods
y: method A argument
z: method B argument
Run Code Online (Sandbox Code Playgroud)
有没有办法明确地将参数标记为属于特定方法/类(不仅仅是在描述中写出)类似于使用部分,或者我应该使用完全不同的结构?