继承 R 包中多个参数的 Roxygen2 文档

Inherit Roxygen2 documentation for multiple arguments in R package

我正在编写一个 R 程序包并希望将两个参数(比如 xy)的文档从一个旧函数(比如 old())继承到一个新函数函数,new()。不同之处在于这两个参数共享相同的参数描述。也就是说,在 old() 函数中,它们被记录在一行中并用逗号分隔,如下所示:

#' @param x,y Two arguments with the same description

我为 new() 使用了以下参数来继承这些参数:

#' @inheritParams old

但是,当我构建包时,new() 的文档列出了 x 而不是 y

有没有办法继承像这样的多个参数?

万一其他人偶然发现了这个,答案是你不能这样做。

这来自 roxygen2 的创造者 Hadley Wickham。

似乎在 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