Search code examples
rr-packageroxygen2

Displaying numbered list in R package


I'm having trouble getting a numbered list to display in R package help.

Here's what I have in roxygen:

#' @return
#' Bunch of text
#' Bunch of text: 
#'  \enumerate {
#'    \item a
#'    \item b
#'    \item c
#' }

This is displaying without numbers. After I save the file, I click Build & Reload in RStudio, then run devtools::document, then devtools::load_all. When I run help on the package, I get the following message in the console:

Using development documentation for function name

Solution

  • A simple space is causing the missing numbers: Just remove the space after enumerate and the first {.

    The second issue is the missing title doc (which causes the documentation build to fail but I guess that is not your problem because you recognized the missing numbers so the build must have succeeded).

    This will work:

    #' My title...
    #' @return
    #' Bunch of text
    #' Bunch of text:
    #'  \enumerate{
    #'    \item a
    #'    \item{b}
    #'    \item{c}
    #' }
    hello1 <- function() {
      print("Hello, world!")
    }
    

    ?hello1 shows then:

    enter image description here

    PS: You can recognize this kind of problem in RStudio in the build log:

    Warning: hello1.Rd:12: unexpected TEXT ' ', expecting '{'

    Edit 1:

    The name of the generated Rd file and the line number within this file is indicated in the warning after the colon (here: 12).

    You find the generated Rd file in the man folder of the package.

    Just open it and look for the line number to examine the problem:

    % Generated by roxygen2: do not edit by hand
    % Please edit documentation in R/hello1.R
    \name{hello1}
    \alias{hello1}
    \title{My title...}
    \usage{
    hello1()
    }
    \value{
    Bunch of text
    Bunch of text:
     \enumerate {         % <- this is line number 12 !!!!
       \item a
       \item{b}
       \item{c}
    }
    }
    \description{
    My title...
    }