保留示例部分中的缩进
Roxygen 让我的工作变得更加轻松,并且在大多数情况下都很好且直观。我从未弄清楚的一件事是如何在 @examples 部分中保留缩进,以便包含的 roxygenize("myPackage")
的结果
#' @examples
#' sapply(1:10, function(i){
#' x <- rbind(matrix(rnorm(20), 10, 2),
#' matrix(rnorm(20), 10, 2) + i)
#' myFunc(x)
#' }
它
\examples{sapply(1:10, function(i){
x <- rbind(matrix(rnorm(20), 10, 2),
matrix(rnorm(20), 10, 2) + i)
myFunc(x)
}}
而不是
\examples{sapply(1:10, function(i){
x <- rbind(matrix(rnorm(20), 10, 2),
matrix(rnorm(20), 10, 2) + i)
myFunc(x)
}}
是一个小细节,但它使所有但最简单的例子不必要地难以阅读,所以如果有人可以帮助我,我将不胜感激。
编辑:此错误在 roxygen 的更高版本中已得到纠正。
Roxygen have made my work a lot easier and is in most cases nice and intuitive. One thing that I have never figured out though is how to preserve indentation in @examples sections so that the result of roxygenize("myPackage")
containing
#' @examples
#' sapply(1:10, function(i){
#' x <- rbind(matrix(rnorm(20), 10, 2),
#' matrix(rnorm(20), 10, 2) + i)
#' myFunc(x)
#' }
would be
\examples{sapply(1:10, function(i){
x <- rbind(matrix(rnorm(20), 10, 2),
matrix(rnorm(20), 10, 2) + i)
myFunc(x)
}}
instead of
\examples{sapply(1:10, function(i){
x <- rbind(matrix(rnorm(20), 10, 2),
matrix(rnorm(20), 10, 2) + i)
myFunc(x)
}}
It is a small detail but it makes all but the simplest examples unnecessarily hard to read so I'd appreciate it if someone can help me.
Edit: This bug was corrected in later versions of roxygen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于简短的示例来说可能开销太大,但对于较长的示例,您可以使用
@examplerelative/path/to/example
来拉入文件,这样应该可以正确缩进。Probably too much overhead for short examples, but for longer examples you could
@example relative/path/to/example
to pull in a file, which should get the indenting right.