roxygen2 manually insert line breaks
Asked Answered
K

1

37

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?

Knowing answered 16/9, 2013 at 19:3 Comment(6)
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.Thibodeaux
Might look nice for a bullet (or numbered) list, use \itemize or \enumerate.Francefrancene
@shujaa That's an excellent suggestion, I'll look into that.Knowing
@Knowing for an example of syntax, run ggplot2:::rd_aesthetics("geom", "point") (ggplot2 has a programmatic approach to certain parts of the documentation).Francefrancene
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?Depressant
@Depressant If that doesn't work post a new question with example code.Thibodeaux
T
64

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

Thibodeaux answered 11/6, 2014 at 14:34 Comment(5)
@Depressant 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.Thibodeaux
Not being able to put a newline in the comments makes that option even worse. I'll add it at the end.Depressant
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.Sclerodermatous
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.Siloa
@DanChaltielI learned that stuff through: cran.r-project.org/doc/manuals/r-release/…Thibodeaux

© 2022 - 2024 — McMap. All rights reserved.