Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax for using pandoc with RStudio Markdown for conversion to MS Word? How can it be used to include bibliography and inline citations?

RStudio now supports directly knitting .Rmd files into docx format --pure gold for someone who is the technical side of most collaborations where the final revisions of the article are going to be done in Word.

However, I had just barely figured out how to get R, knitr, and pandoc to play with each other and so I am looking for some help in making the transition while the documentation is still in its infancy.

My file converts with no problem using the yaml code block as follows:

---
title: "Testing"
output: 
  word_document:
    fig_width: 5
    fig_height: 5
    fig_caption: true
---

and the documentation says that, assuming I have a file 'myLibrary.bib' in the same directory as my .Rmd file, I should be able to add something like this:

    pandoc_args: [
      bibliography: "myLibrary.bib"
    ]

or

pandoc_args: [
      --bibliography "myLibrary.bib"
    ]

but I can't seem to find any examples of how to format this in the obvious places: here or here

Bonus points for code that also links the bibliography to the myJournalFormat.csl file also in the same folder.

like image 550
csfowler Avatar asked May 20 '14 20:05

csfowler


People also ask

How do I convert Word to markdown in pandoc?

As you can see, first, write pandoc to execute any pandoc command, and then write the file name of a file with extension which you want to convert to a markdown file. The -o stands for output file name and provide name of the file with extension to which it should be converted.

How do you add a citation in R Markdown?

Inserting Citations. You insert citations by either using the Insert -> Citation command or by using markdown syntax directly (e.g. [@cite] or @cite ) . Citations go inside square brackets and are separated by semicolons.


2 Answers

You need to enclose your arguments in quotation marks, ("") and be separated by commas

If I have a bibliography file called biblio.bib and the csl file is chicago-author-date.csl,

the following will front matter will work

---
title: "Example Doc"
output:
  word_document:
    pandoc_args: [
      "--csl", "chicago-author-date.csl",
      "--bibliography", "biblio.bib"
    ]
---
like image 195
mnel Avatar answered Oct 27 '22 21:10

mnel


I had the same problem you have. Perhaps not a real answer to your question, but you might want to take a look at David Gohel's r package ReporteRs http://davidgohel.github.io/ReporteRs/gettingstarted.html He made it easy to let r generate .docx files. I have already had astonishing results!

like image 36
rdatasculptor Avatar answered Oct 27 '22 21:10

rdatasculptor