3

I have a specific question, but then a "teach a man to fish" question...

I am writing an R package using Reference Classes. As described here, I am placing docstrings within each method, which roxygen then picks up and places into the class' documentation (Rd) file. Here is an example method along with the docstring:

MyClass$methods(mymethod = function(argument) {
  "Do something useful
  \\subsection{Parameters}{
  \\itemize{
  \\item{\\code{argument} A useful argument.}
  }}
  \\subsection{Return Value}{Always returns 42}
  \\subsection{Example}{
  \\code{ cl <- MyClass$new() }
  \\code{ cl$mymethod() } 
  \\code{ cl$mymethod(12) }}"
  return(42)
})

The problem with this is that all my code in the "example" section ends up on one line:

cl <- MyClass$new() cl$mymethod() cl$mymethod(12)

So my immediate question is: how do I break the lines in my example code?

And my "teach a man to fish" question is, where is this docstring syntax for R documented? All my googling thus far has come up with docstring documentation for other languages that seems to have quite a different syntax and format.

Thank you!

Eric
  • 1,691
  • 16
  • 24
  • 1
    Take a look at [Marking Text](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Marking-text) in the Writing R Extensions manual. There is actually an `\\examples` section as well that you might want to use. See the [Documenting Functions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Documenting-functions) section. – MrFlick May 24 '17 at 15:01
  • Ahhhh...I get it. The docstring is in Rd format. Obvious now that you say it =). Feel free to make that an answer and I'll accept! – Eric May 24 '17 at 15:13

0 Answers0