roxygen2 manually insert line breaks

Zach picture Zach · Sep 16, 2013 · Viewed 8.9k times · Source

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?

Answer

Tyler Rinker picture Tyler Rinker · Jun 11, 2014

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).