当多个参数匹配时,如何在单个参数上使用@inheritParams? [英] How to use @inheritParams on single parameters when multiple parameters match?
问题描述
当多个参数名称匹配时,我想记录R函数并从其他函数继承单个参数文档。例如,假设我具有以下两个函数。
I would like to document an R function and inherit individual parameter documentation from other functions when multiple parameter names match. For example, lets say I have the following 2 functions.
#' Function 1.
#'
#' Description of function 1.
#'
#' @param x XYZ
#' @param y ZYX
#' @return Numeric
fun1 <- function(x, y) {value <- 1}
#' Function 2.
#'
#' Description of function 2.
#'
#' @param x ABC
#' @param y CBA
#' @return Numeric
fun2 <- function(x, y) {value <- 2}
我现在想创建第三个函数,该函数继承fun1的参数x和fun2的参数y。以下内容不起作用:
I now want to create a third function that inherits parameter x from fun1 and parameter y from fun2. The following do not work:
#' Function 3.
#'
#' Description of function 3.
#'
#' @inherit fun1 params x
#' @inherit fun2 params y
fun3 <- function(x, y) {value <- 3}
#' Function 3.
#'
#' Description of function 3.
#'
#' @inheritParams fun1 x
#' @inheritParams fun2 y
fun3 <- function(x, y) {value <- 3}
如果执行以下操作,则两个参数都将从fun1继承:
If you do the following then both parameters are inherited from fun1:
#' Function 3.
#'
#' Description of function 3.
#'
#' @inheritParams fun1
#' @inheritParams fun2
fun3 <- function(x, y) {value <- 3}
我不确定还有什么尝试或
I'm not sure what else to try or if this is even possible?
推荐答案
您可以将 roxygen2
模板用于
- 创建一个名为
man-roxygen
的文件夹。 - 将其添加到
.Rbuildignore
,并在其后附加^ man-roxygen
。 - 在该文件夹中,您可以创建带文档摘要的R文件。
例如,假设您有一个文件x-arg.R
包含:
-
#'@param x My x参数。
- Create a folder called
man-roxygen
. - Add it to
.Rbuildignore
by appending a line with^man-roxygen
. - Inside that folder you can create R files with documentation snippets.
For instance, let's say you have a file
x-arg.R
with:#' @param x My x parameter.
编辑:此外,您可以拥有多个
@param
每个模板条目(如果适合您的用例)。also, you can have more than one
@param
entry per template if it fits your use case.我相信这适用于几乎所有类型的文档您想重复一遍,
,尽管某些情况下需要特殊处理。
例如,如果您想要一个模板,该模板的某些文本应放在特定部分(例如 Details)下,则
R模板文件中的代码段也必须具有相应的指令
,然后使用它,如果您还有其他特定文本,则可能需要重复该指令:I believe this works for pretty much any kind of documentation you want to repeat, though some cases require special handling. For example, if you wanted to have a template with some text that should go under a specific section (e.g. "Details"), the snippet in the R template file must also have the corresponding directive, and then to use it you might need to repeat the directive if you have additional specific text:
在
details-template.R
#' @details #' #' Text that should appear everywhere
要使用它
#' @details #' #' Some specific text. #' #' @template details-template
这篇关于当多个参数匹配时,如何在单个参数上使用@inheritParams?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-