开发者

Preserving indentation in examples section

开发者 https://www.devze.com 2023-03-26 23:20 出处:网络
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 o

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(开发者_StackOverflowmatrix(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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消