Overview

To create an OpenDocument Text (ODT) document from R Markdown you specify the odt_document output format in the front-matter of your document:

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

Figure Options

There are a number of options that affect the output of figures within ODT documents:

  • fig_width and fig_height can be used to control the default figure width and height (5x4 is used if not values are specified)

  • fig_caption controls whether figures are rendered with captions

For example:

---
title: "Habits"
output:
  odt_document:
    fig_width: 5
    fig_height: 5
    fig_caption: true
---

Advanced Customization

Style Reference

You can also specify a document to be used as as a style reference in producing an odt file. For best results, the reference odt should be a modified version of an odt file produced using rmarkdown. Pass “default” to use the default styles. You can do this with the reference_odt option:

---
title: "Habits"
output:
  odt_document:
    reference_odt: mystyles.odt
---

Includes

You can do more advanced customization of output by including additional ODT content or by replacing the core pandoc template entirely. To include content in the document header or before/after the document body you use the includes option as follows:

---
title: "Habits"
output:
  odt_document:
    includes:
      in_header: header.odt
      before_body: doc_prefix.odt
      after_body: doc_suffix.odt
---

Custom Templates

You can also replace the underlying pandoc template using the template option:

---
title: "Habits"
output:
  odt_document:
    template: mytemplate.odt
---

Consult the documentation on pandoc templates for additional details on templates. You can also study the default ODT template as an example.

Keeping Markdown

When knitr processes an R Markdown input file it creates a markdown (md) file which is subsequently tranformed into a Word 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:
  odt_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:
  odt_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.

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 delimeters or enclosing output object are used in this file. For example:

_output.yaml

odt_document:
  fig_width: 5
  fig_height: 5
  fig_caption: true

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