RMarkdown is a convenient tool to write reports containing R code

.bb text above figures in PDFs


Call files and data sources

  • The compiler assumes called files are in the same directory

Change the language of the PDF output

When you output a RMarkdown file in PDF, you obtain a table of contents. If you want to change the title of this table into a different langage, use this in the YAML header (source):

lang: fr-FR
title: "Titre du document"

You can find the right language code here.

Combine different files together

When writing long reports, it is usually easier to split the main file in several smaller files, as you may do with [latex]\LaTeX[/latex].


Export to PowerPoint


Inline code

R Markdown can evaluate inline code too, in two different ways.

In both cases, the code is evaluated[mfn]i.e. the code runs and displays the output/result.[/mfn].

First, once evaluated the code can be outputted as text:

`r nrow(df)`

Second, the code can also outputted as “code”:

```r nrow(df)```

Percentage signs in PDF

% denote comments in [latex]\LaTeX[/latex]. If you write a percentage sign somewhere in a Rmd file, [latex]\LaTeX[/latex] won’t be able to compile it and will throw an error. To avoid this error, you need to espace by using


It’s that simple!

In the preamble, it’s possible to declare the date of the document. But in a fast-pacing environment, one may want to have a similar functionality as \today in [latex]\LaTeX[/latex] (that prints the today’s date).

To emulate such a feature, use this:

date: "`r format(Sys.time(), '%d %B, %Y')`"

The specific formatting of the date can be adjusted in the second part of format() (see https://www.statmethods.net/input/dates.html).


To print nice tables, use the kable function offered by knitr:


Also: formattable (https://renkun-ken.github.io/formattable/).

Do not miss my upcoming posts
★ Subscribe to my newsletter