Installation complement - knitting for .docx and .pdf files

1 Easy fix from a fresh R installation (simple way)

You might need to modify some options in Rstudio.

Go to Tools -> Global Options -> Sweave panel,

Change Sweave to knitr in the “Weave Rnw files using” drop down menu. Then change pdf latex to Xelatex

The options should look like that
The options should look like that

Then click apply at the bottom of the window (you need to scroll, it can be hidden). It will ask you to modify this also for the current project. Do it (it is the same options). Then click apply at the bottom of the window and close the window.

Then install the following package in R (type in the Rstudio console)

install.packages(
  tinytex::install_tinytex()
  )

You are ready to test if this work. Create a new markdown document and knit it as pdf

2 Testing or changing the rendering format for your files

You can try to render a pdf (portable document format), .html (webpage) or .docx (word document) file from an Rmarkdown file (.Rmd) by clicking on the knit button.

Which format your document is rendered is determined by the header of your R markdown document.

output: pdf_document # for pdf document
output: html_document # for html document
output: word_document # for word document

3 Going further: installing Pandoc

Pandoc is a universal document converter, ie: it allows to translate / save document from one type eg. Rmarkdown .Rmd to another eg. word document .docx or many other formats, eg. portable document .pdf. The list of the formats you can convert from and to is given on the pandoc website. If you use pandoc alone to convert between types, the conversion of the formatting (how it looks like) might not be exactly as you wish but it does certainly help to go faster in the process.

Pandoc, when used directly from Rstudio to render your Rmarkdown files (.Rmd file containing both codes and notes) as a word document (.docx) is a very powerful tool, because the integration of Rstudio and pandoc is very well done.

The description and development website for this package (a github repository) can be found here

To install the pandoc package in R, type the following line in Rstudio console:

install.packages("pandoc")
  • download the latest version of the installer for windows from the pandoc website

The version you have to choose should look like : pandoc-<version>-windows-x86_64.msi

Then double click on this file to install it, and follow the default instructions for installation.

You might need to modify some options in Rstudio.

Go to Tools -> Global Options -> Sweave panel,

Change Sweave to knitr in the “Weave Rnw files using” drop down menu. Then click apply at the bottom of the window and close the window.

LS0tDQp0aXRsZTogImByIHBhcmFtcyR0aXRsZWAiDQpkYXRlOiAiYHIgZm9ybWF0KFN5cy50aW1lKCksICclZCAlQiwgJVknKWAiDQphdXRob3I6IEV2ZSBaZXlsIEZpc2tlYmVjayBhbmQgTWFkZWxhaW5lIE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