12

I'm wondering if it's possible to insert newlines inside code blocks in roxygen2 when documenting a function?

If I have something inside \code{}, roxygen2 collapses all newlines into single spaces by default. I tried inserting \cr inside to enforce a line break, and I get the desired behaviour, but then I get a WARNING when I "R CMD CHECK". Is there a way to do this?

Example:

#' \code{
#'   multiple
#'   lines
#' }
Backlin
  • 14,612
  • 2
  • 49
  • 81
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • Note that this is not really a roxygen issue but rather a general R documentation issue, see [the manual](http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Marking-text). – Backlin May 25 '15 at 08:58

1 Answers1

21

Use \preformatted instead of \code. \code is for inline code (works like `` on SO) and \preformatted is for verbatim blocks (like indentation on SO).

#' \preformatted{
#'   multiple
#'   lines
#' }

Note that the initial line break, just after {, will also be part of the code block, so you might want to consider removing it.

Backlin
  • 14,612
  • 2
  • 49
  • 81