Overview

To create an RTF document from R Markdown you specify the rtf_document output format in the front-matter of your document:

---
title: "Habits"
author: John Doe
date: March 22, 2005
output: rtf_document
---

Table of Contents

You can add a table of contents using the toc option and specify the depth of headers that it applies to using the toc_depth option. For example:

---
title: "Habits"
output:
  rtf_document:
    toc: true
    toc_depth: 2
---

If the table of contents depth isn’t explicitly specified then it defaults to 3 (meaning that all level 1, 2, and 3 headers will be included in the table of contents).

Figure Options

The fig_width and fig_height options can be used to control the default figure width and height (5x4 is used if not values are specified). For example:

---
title: "Habits"
output:
  rtf_document:
    fig_width: 5
    fig_height: 5
---

Keeping Markdown

When knitr processes an R Markdown input file it creates a markdown (md) file which is subsequently transformed into an RTF document by pandoc. If you want to keep a copy of the markdown file after rendering you can do so using the keep_md option:

---
title: "Habits"
output:
  rtf_document:
    keep_md: true
---

Markdown Extensions

By default R Markdown is defined as all pandoc markdown extensions with the following tweaks for backward compatibility with the markdown package:

+autolink_bare_uris
+ascii_identifier
+tex_math_single_backslash

You can enable or disable markdown extensions using the md_extensions option (you preface an option with - to disable and + to enable it). For example:

---
title: "Habits"
output:
  rtf_document:
    md_extensions: -autolink_bare_uris+hard_line_breaks
---

The above would disable the autolink_bare_uris extension and enable the hard_line_breaks extension.

For more on available markdown extensions see the pandoc markdown specification.

Pandoc Arguments

If there are pandoc features you want to use that lack equivalents in the YAML options described above you can still use them by passing custom pandoc_args. For example:

---
title: "Habits"
output:
  rtf_document:
    pandoc_args: [
      "--csl", "/var/csl/acs-nano.csl"
    ]
---

Documentation on all available pandoc arguments can be found in the pandoc user guide.

Shared Options

If you want to specify a set of default options to be shared by multiple documents within a directory you can include a file named _output.yaml within the directory. Note that no YAML delimiters or enclosing output object are used in this file. For example:

_output.yaml

rtf_document:
  fig_width: 5
  fig_height: 5

All documents located in the same directory as _output.yaml will inherit it’s options. Options defined explicitly within documents will override those specified in the shared options file.

comments powered by Disqus