全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 LATEX论坛
1847 1
2016-06-18

To create a Word document from R Markdown you specify the word_document output format in the front-matter of your document:

---title: "Habits"author: John Doedate: March 22, 2005output: word_document---


Figure Options

There are a number of options that affect the output of figures within Word 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:  word_document:    fig_width: 5    fig_height: 5    fig_caption: true---


Syntax Highlighting

You can use the highlight option to control the syntax highlighting theme. For example:

---title: "Habits"output:  word_document:    highlight: "tango"---

Supported styles include “default”, “tango”, “pygments”, “kate”, “monochrome”, “espresso”, “zenburn”, and “haddock”. Pass null to prevent syntax highlighting.



Style Reference

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

---title: "Habits"output:  word_document:    reference_docx: mystyles.docx---


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 thekeep_md option:

---title: "Habits"output:  word_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:  html_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 equivilants in the YAML options described above you can still use them by passing custom pandoc_args. For example:

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

_output.yaml

word_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.



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-6-18 15:40:15
oliyiyi 发表于 2016-6-18 15:00
To create a Word document from R Markdown you specify the word_document output format in the front-m ...
谢谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群