【发布时间】:2014-09-30 10:05:33
【问题描述】:
使用 roxygen2 记录函数时,可以将示例放在单独的文件中。
请看这里:http://r-pkgs.had.co.nz/man.html “您可以将示例放在单独的文件中,然后使用 @example path/relative/to/packge/root 将它们插入到文档中,而不是将示例直接包含在文档中。”
这里:http://roxygen.org/roxygen2-manual.pdf
例如
#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of \code{x} and \code{y}.
#' @example /path/to/example/add.R
add <- function(x, y) {
x + y
}
我的问题是:应该使用什么路径来存储示例 R 文件?
【问题讨论】:
-
我认为 /inst/ 移动到 / 时安装包?如果文档已经构建,我想这并不重要?
-
是的,
inst/examples应该移动到examples,然后我认为您可以在文档中引用/examples。 -
OK inst/examples 运行良好。我可以在源代码中引用 /inst/examples/file.R,然后使用 devtools::document() 创建文档。 /inst/examples 移动到 /examples,但我认为这无关紧要,因为文档已经构建...
-
我无法确定这是否是个好主意。它使运行您的示例变得更容易一些,但 roxygen 的全部意义不在于您将文档放在定义函数的位置旁边吗?