在R包中继承Roxygen2文档以处理多个参数

9
我正在编写一个 R 包,想要从旧函数(比如 old())中继承两个参数(比如 x 和 y)的文档到新函数(比如 new())。问题在于这两个参数共享相同的参数描述。也就是说,在 old() 函数中,它们被记录在单行中,用逗号分隔,像这样:
#' @param x,y 具有相同描述的两个参数
我使用以下代码来让 new() 继承这些参数:
#' @inheritParams old
但是,当我构建包时,new() 的文档列出了 x,但没有列出 y。
有没有一种方法可以继承这样的多个参数?
2个回答

10

如果有其他人遇到同样的问题,答案是你无法这样做。

这是来自roxygen2的创始人Hadley Wickham的说法。


4

看起来在6.1.1版本中,你可以使用new(),唯一的缺点是两个变量会有相同的描述但会分别列出。我尝试写了一个可重现的示例。

# roxygen 6.1.1, devtools 2.0.1, usethis 1.4.0
# Select a project folder and do setwd(<project_folder>)
usethis::create_package("inheritanceTest")
setwd("./inheritanceTest")

t = "
#' Hello
#'
#' @param x,y some stuff
#'
#' @return other stuff
#' @export
test_inherit_parent = function(x,y){
  print('Hello')
}

#' Hello2
#'
#' @inheritParams test_inherit_parent
#'
#' @return other stuff2
#' @export
test_inherit_child = function(x,y){
  print('Hello2')
}
"
fileConn = file("./R/functions.R")
writeLines(t, fileConn)
close(fileConn)
devtools::document()
devtools::load_all(".")
?test_inherit_parent
?test_inherit_child

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接