R: A Pandoc wrapper to convert documents to other formats

pandoc {knitr} | R Documentation

## A Pandoc wrapper to convert documents to other formats

### Description

This function calls Pandoc to convert documents to other formats such as HTML, LaTeX/PDF and Word, etc, (optionally) based on a configuration file or in-file configurations which specify the options to use for Pandoc.

### Usage

    pandoc(input, format, config = getOption("config.pandoc"), ext = NA,
        encoding = getOption("encoding"))

### Arguments

`input` | a character vector of the Markdown filenames
`format` | the output format (see References); it can be a character vector of multiple formats; by default, it is obtained from the `t` field in the configuration (if the configuration is empty or the `t` field is not found, the default output format will be `'html'`)
`config` | the Pandoc configuration file; if missing, it is assumed to be a file with the same base name as the `input` file and an extension `.pandoc` (e.g. for ‘foo.md’ it looks for ‘foo.pandoc’)
`ext` | the filename extensions; by default, the extension is inferred from the `format`, e.g. `latex` creates `pdf`, and `dzslides` creates `html`, and so on
`encoding` | the encoding of the input file; see `file`

### Details

There are two ways to input the Pandoc configurations – through a config file, or embed the configurations in the input file as special comments between `<!--pandoc` and `-->`.

The configuration file is a DCF file (see `read.dcf`). This file must contain a field named `t` which means the output format. The configurations are written in the form of `tag:value` and passed to Pandoc (if no value is needed, just leave it empty, e.g. the option `standalone` or `s` for short). If there are multiple output formats, write each format and relevant configurations in a block, and separate blocks with blank lines.

If there are multiple records of the `t` field in the configuration, the input markdown file will be converted to all these formats by default, unless the `format` argument is specified as one single format.

### Value

The output filename(s) (or an error if the conversion failed).

### References

Pandoc: http://pandoc.org; Examples and rules of the configurations: https://yihui.name/knitr/demo/pandoc/

Also see R Markdown (v2) at http://rmarkdown.rstudio.com. The rmarkdown package has several convenience functions and templates that make it very easy to use Pandoc. The RStudio IDE also has comprehensive support for it, so I'd recommend users who are not familiar with command-line tools to use the rmarkdown package instead.

### See Also

`read.dcf`

### Examples

    system("pandoc -h")  # see possible output formats

[Package knitr version 1.16 Index]