将@example标记与roxygen2一起使用时文件的位置

waf*_*hin 8 r roxygen2

使用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
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:应该使用什么路径来存储示例R文件?

And*_*rie 5

氧气中使用的示例的适当位置是:

inst/examples/
Run Code Online (Sandbox Code Playgroud)

氧气线应为:

#' @example inst/examples/add.R
Run Code Online (Sandbox Code Playgroud)

这是好习惯吗?我认为是这样,因为:

  • 它使开发过程中的示例运行,修改和测试更加容易
  • 这样就可以(至少在原则上)在文档的不同位置(例如在小插图中)重复使用示例