9

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{}?

needRhelp
  • 2,948
  • 2
  • 24
  • 48
  • 1
    H. Wickham says this: http://r-pkgs.had.co.nz/man.html. In my own packages I also use `\ţabular{}` and the syntax is similar to LaTex. – J_F Mar 15 '17 at 15:02
  • Currently supported tags: https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html – hrbrmstr Mar 15 '17 at 16:19

2 Answers2

3

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.

Hugh
  • 15,521
  • 12
  • 57
  • 100
1

Note that {roxygen} generates R Documentation files in the end. Thus, you can always go to the Writing R Extensions: Lists and tables and write the table in the native documentation language for R-packages by hand.

Here's a minimal example:

\name{dummy}
\title{Dummy}
\details{
  The example here is:
\tabular{lcc}{
  Tables   \tab  Are           \tab Cool   \cr
  col 3 is \tab  right-aligned \tab $1600  \cr
  col 2 is \tab  centered      \tab  $12   \cr
 }
}

Note, that the latest {roxygen2} version 7.0 provides more support for markdown-syntax.

Mossa
  • 1,656
  • 12
  • 16