Knitting the report

Producing the final RMarksdown report is called “knitting”. When you are editing the RMarkdown script, you will see a special option to “Knit”" at the top of the script, near the save shortcut button. Clicking “Knit” will begin the process of creating the final document. The option to “Knit” does not appear for normal R scripts, only RMarkdown scripts.

Note the following:

  • You can use the arrow next to the word “Knit” to select the type of document you want to produce: Microsoft Word, PDF, or HTML (HTML opens the file in an offline web browser). Note that to knit to a PDF directly, additional packages may have to be installed.

  • The default document type is specified in the header of the RMarkdown script, and for the templates it is Microsoft Word.

Knit the template you have edited and review the results. You may find that helper text you left in the template appears - go back and delete it from the script.

If you receive an error when knitting such as “openBinaryFile does not exist … Error: pandoc document conversion failed with error 1”, your R project file may be saved in a location with restricted permissions such as a network drive. The RMarkdown is likely not permitted to write the new Microsoft Word file to that location. Try saving your R project to a more local location on your computer.

If you are on an MSF computer, try writing saving the R project on the C drive where you have read/write rights - in general this is the c:temp folder.

Adding additional text to the report

You can add text to the report by typing into the write space of the template script (non-R chunks). You may want to write a more substantial introductory or summary paragraph at the beginning of the document.

It is also possible to write in-line code - this is where in the script text you put a placeholder for a number or output that is calculated from your data. This way, the number adapts to your data and does updates automatically. Examples of this are found throughout the template.

To write in-line code, write your sentence in the script’s white space like normal text, but in place of the number put a one-line R command within backticks (). Ensure the R command returns the desired number.


Table outputs can require post-Knitting adjustment to suitably appear in the final Word Document report. Reducing the number of digits used in the kable() commands that produce the table can help save width.

Dealing with warnings

After knitting, you may see warning text in your final report. Sometimes these warnings are innocuous (e.g. you tried to filter out a factor level that doesn’t exist), but sometimes they are more serious. Typically, it is recommended to read through the warnings and fix them if necessary (see the R Basics - Errors and Warnings page.

One option is to add warning = FALSE, message = FALSE to the top of the R code chunk that produced the warning. This code goes within the opening brackets that create the code chunk. They should be preceeded by a comma.