35

I have a function I am trying to document with roxygen2:

#' Name of function
#' 
#' Description
#' 
#' @param x The input data
#' @param method one of:
#' "method1" - very long text here 
#' "method2" - very long text here
#' "method3" - very long text here
#' "method4" - very long text here 
#' "method5" - very long text here 
#' "method6" - very long text here 
#' "method7" - very long text here 
#' "method8" - very long text here 
#' "method9" - very long text here 
#' "method10" - very long text here 
myfun <- function (x, method){return(NULL)}

This function has about 10 different methods, each of which has a very long description. I want a newline between each "method," to make it easy to quickly see the different methods available.

As written, when I call roxygenize('mypackage'), the above text get squashed into a single line.

How do I manually insert line breaks into roxygen2 documentation?

Zach
  • 29,791
  • 35
  • 142
  • 201
  • 4
    Then hit the return button on your computer after x (I use 80) width. In RStudio the `#' ` gets inserted in automatically. In some cirumstances you need to add `\cr` to break a line. – Tyler Rinker Sep 16 '13 at 19:08
  • 2
    Might look nice for a bullet (or numbered) list, use `\itemize` or `\enumerate`. – Gregor Thomas Sep 16 '13 at 20:28
  • @shujaa That's an excellent suggestion, I'll look into that. – Zach Sep 16 '13 at 21:57
  • @Zach for an example of syntax, run `ggplot2:::rd_aesthetics("geom", "point")` (ggplot2 has a programmatic approach to certain parts of the documentation). – Gregor Thomas Sep 16 '13 at 23:00
  • I'm also having difficulty with this. Where does the `\cr` belong? At the end of the first line? At the beginning of the second line? In between them in its own line? I've tried all of these with no luck. @Tyler Rinker could you submit an answer with an example? – rnorberg Jun 11 '14 at 13:27
  • @rnorberg If that doesn't work post a new question with example code. – Tyler Rinker Jun 11 '14 at 14:35

1 Answers1

56

This works:

#' Name of function
#' 
#' Description
#' 
#' @param x The input data
#' @param method one of: \cr 
#' "method1" - very long text here \cr 
#' "method2" - very long text here \cr 
#' "method3" - very long text here \cr 
#' "method4" - very long text here \cr 
#' "method5" - very long text here \cr 
#' "method6" - very long text here \cr 
#' "method7" - very long text here \cr 
#' "method8" - very long text here \cr 
#' "method9" - very long text here \cr 
#' "method10" - very long text here \cr 
myfun <- function (x, method){return(NULL)}

Here is an actual example in a repo where I use \cr: https://github.com/trinker/SOdemoing/blob/master/R/FUN.R

Also @Gregor's comment is well taken. That would look like:

#' @param method2 one of:
#' \itemize{
#'   \item method1 - very long text here 
#'   \item method2 - very long text here
#'   \item method3 - very long text here
#'   \item method4 - very long text here 
#'   \item method5 - very long text here 
#'   \item method6 - very long text here 
#'   \item method7 - very long text here 
#'   \item method8 - very long text here 
#'   \item method9 - very long text here 
#'   \item method10 - very long text here 
#' }

Here you can see the output for both:

enter image description here

I created a GitHub repo, SOdemoing, to test things like this (more elaborate package related questions and answers) out. See FUN.R where I test both approaches using roxygen2 and then the resulting help manual where I set this up (again the function is FUN.R).

Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
  • 1
    @rnorberg your edit enables other ways of seeing but tremendously disrupted the flow of meaning. I rolled back the edit. I think you could add as a comment or as an edit at the end of the post. – Tyler Rinker Jun 11 '14 at 18:50
  • 1
    Not being able to put a newline in the comments makes that option even worse. I'll add it at the end. – rnorberg Jun 11 '14 at 18:56
  • 3
    If you are building an R package be carefull with "\cr" in the R documentation files (*.Rd). In these files "\cr" needs to be placed after text (aka not a line by itlsef) else LaTeX fails in the generation of the pdf version of the documentation. – Kristoffer Vitting-Seerup Apr 20 '17 at 11:28
  • Do you know any comprehensive list of such tags? `\cr` seems to mean "column row", I'm really curious as to how you manage to find this out. – Dan Chaltiel Apr 07 '20 at 15:57
  • @DanChaltielI learned that stuff through: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Lists-and-tables – Tyler Rinker Apr 09 '20 at 14:02