Preserving indentation in examples section
Asked Answered
P

1

7

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.

Phagocyte answered 8/8, 2011 at 13:19 Comment(4)
Are you using roxygen or roxygen2? I'm pretty sure this doesn't happen in roxygen2, and if it does it's a bug, and should be reported.Caro
I was using plain old roxygen but the problem remained after I updated to roxygen2. gsk3's solution works for both though but I guess it better be reported anyway. How do I do that?Phagocyte
Please submit a reproducible bug report at github.com/klutometis/roxygen/issuesCaro
Here it is github.com/klutometis/roxygen/issues/27.Phagocyte
C
4

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.

Climax answered 8/8, 2011 at 14:31 Comment(1)
Thanks, it works like a charm! The overhead isn't that bad too since it only applies to some occasional examples, especially when compared to the prohibitively large burden of manually correcting the indentation.Phagocyte

© 2022 - 2024 — McMap. All rights reserved.