Search code examples
rmarkdownroxygen2

Insert markdown table in roxygen2 R package documentation


I'm writing an R package and I want to include a table in an R help file, e.g. in the @details section. I tried including markdown code directly:

#' | Tables        | Are           | Cool  |
#' | ------------- |:-------------:| -----:|
#' | col 3 is      | right-aligned | $1600 |
#' | col 2 is      | centered      |   $12 |

But this does not give me the desired output. I have enabled markdown support for the whole package and have roxygen2 6.0.1 installed. Is there no support for markdown tables? Do I have to use \tabular{}?


Solution

  • You need to add the @md tag to your roxygen chunk

    #' @details
    #' The table is: 
    #'
    #' | Tables        | Are           | Cool  |
    #' | ------------- |:-------------:| -----:|
    #' | col 3 is      | right-aligned | $1600 |
    #' | col 2 is      | centered      |   $12 |
    #' 
    #' @md
    

    or add Roxygen: list(markdown = TRUE) to your DESCRIPTION file.