1 Prerequisites

Bioconductor R Markdown format is build on top of R package bookdown (Xie, Allaire, and Grolemund 2018), which in turn relies on rmarkdown and pandoc to compile the final output document. Therefore, unless you are using RStudio, you will need a recent version of pandoc (>= 1.17.2). See the pandoc installation instructions for details on installing pandoc for your platform.

2 Getting started

To enable the Bioconductor style in your R Markdown vignette you need to:

  • Edit the DESCRIPTION file by adding

      VignetteBuilder: knitr
      Suggests: BiocStyle, knitr, rmarkdown
  • Specify BiocStyle::html_document or BiocStyle::pdf_document as output format and add vignette metadata in the document header:

      ---
      title: "Vignette Title"
      author: "Vignette Author"
      package: PackageName
      output: 
        BiocStyle::html_document
      vignette: >
        %\VignetteIndexEntry{Vignette Title}
        %\VignetteEngine{knitr::rmarkdown}
        %\VignetteEncoding{UTF-8}  
      ---

The vignette section is required in order to instruct R how to build the vignette.1 \VignetteIndexEntry should match the title of your vignette The package field which should contain the package name is used to print the package version in the output document header. It is not necessary to specify date as by default the document compilation date will be automatically included. See the following section for details on specifying author affiliations and abstract.

BiocStyle’s html_document and pdf_document format functions extend the corresponding original rmarkdown formats, so they accept the same arguments as html_document and pdf_document, respectively. For example, use toc_float: true to obtain a floating TOC as in this vignette.

2.1 Use with R markdown v1

Apart from the default markdown engine implemented in the rmarkdown package, it is also possible to compile Bioconductor documents with the older markdown v1 engine from the package markdown. There are some differences in setup and the resulting output between these two engines.

To use the markdown vignette builder engine:

  • Edit the DESCRIPTION file to include

      VignetteBuilder: knitr
      Suggests: BiocStyle, knitr
  • Specify the vignette engine in the .Rmd files (inside HTML comments)

      <!--
      %% \VignetteEngine{knitr::knitr}
      -->
  • Add the following code chunk at the beginning of your .Rmd vignettes

      ```{r style, echo = FALSE, results = 'asis'}
      BiocStyle::markdown()
      ```

The way of attaching CSS files when using markdown differs from how this is done with rmarkdown. In the former case additional style sheets can be used by providing them to the BiocStyle::markdown function. To include custom.css file use

```{r style, echo = FALSE, results = 'asis'}
BiocStyle::markdown(css.files = c('custom.css'))
```

3 Document header

3.1 Author affiliations

The author field allows for specifying author names along with affiliation and email information.

In the basic case, when no additional information apart from author names is provided, these can be entered as a single character string

author: "Single Author"

or a list

author:
- First Author
- Second Author
- Last Author

which will print as “First Author, Second Author and Last Author”.

Author affiliations and emails can be entered in named sublists of the author list. Multiple affiliations per author can be specified this way.

author:
- name: First Author
  affiliation: 
  - Shared affiliation
  - Additional affiliation
- name: Second Author
  affiliation: Shared affiliation
  email: corresponding@author.com

A list of unique affiliations will be displayed below the authors, similar as in this document.

For clarity, compactness, and to avoid errors, repeated nodes in YAML header can be initially denoted by an anchor entered with an ampersand &, and later referenced with an asterisk *. For example, the above affiliation metadata is equivalent to the shorthand notation

author:
- name: First Author
  affiliation: 
  - &id Shared affiliation
  - Additional affiliation
- name: Second Author
  affiliation: *id
  email: corresponding@author.com

3.2 Abstract and running headers

Abstract can be entered in the corresponding field of the document front matter, as in the example below.

---
title: "Full title for title page"
shorttitle: "Short title for headers"
author: "Vignette Author"
package: PackageName
abstract: >
  Document summary
output: 
  BiocStyle::pdf_document
---

The shorttitle option specifies the title used in running headers instead of the document title.2 only relevant to PDF output

4 Style macros

BiocStyle introduces the following macros useful when referring to R packages:

  • Biocpkg("IRanges") for Bioconductor software, annotation and experiment data packages, including a link to the release landing page or if the package is only in devel, to the devel landing page, IRanges.

  • CRANpkg("data.table") for R packages available on CRAN, including a link to the FHCRC CRAN mirror landing page, data.table.

  • Githubpkg("rstudio/rmarkdown") for R packages available on GitHub, including a link to the package repository, rmarkdown.

  • Rpackage("MyPkg") for R packages that are not available on Bioconductor, CRAN or GitHub; MyPkg.

These are meant to be called inline, e.g., `r Biocpkg("IRanges")`.

5 Code chunks

The line length of output code chunks is set to the optimal width of typically 80 characters, so it is not neccessary to adjust it manually through options("width").

6 Figures

6.1 Simple figures

BiocStyle comes with three predefined figure sizes. Regular figures not otherwise specified appear indented with respect to the paragraph text, as in the example below.

plot(cars)

A default sized example figure without a caption.

6.2 Figure captions

Figures which have no captions, like the one above, are just placed wherever they were generated in the R code. If you assign a caption to a figure via the code chunk option fig.cap, the plot will be automatically labeled and numbered3 for PDF output it will be placed in a floating figure environment, and it will be also possible to reference it. These features are provided by bookdown, which defines a format-independent syntax for specifying cross-references, see Section 9. The figure label is generated from the code chunk label4 for cross-references to work the chunk label may only contain alphanumeric characters (a-z, A-Z, 0-9), slashes (/), or dashes (-) by prefixing it with fig:, e.g., the label of a figure originating from the chunk foo will be fig:foo. To reference a figure, use the syntax \@ref(label)5 do not forget the leading backslash!, where label is the figure label, e.g., fig:foo. For example, the following code chunk was used to produce Figure 1.

```{r plot, fig.cap = "Regular figure. The first sentence...", echo = FALSE}
plot(cars)
```