7

I am trying to output a date in German long format (today's date would be "28. September 2016") at the beginning of a line in a rmarkdown document. Adding a dot after the day results in extra space before and after the day in the output document however.

---
title: "german long date in rmarkdown"
output: html_document
---

**Date without dot**

`r format(Sys.Date(), "%d %B %Y")`  

**Date with dot**

`r format(Sys.Date(), "%d. %B %Y")`

german long date in rmarkdown

What can I do to remedy this?

dpprdan
  • 1,727
  • 11
  • 24
  • 1
    https://github.com/rstudio/rmarkdown/issues/145 You have to escape: "28\\. September 2016" – jogo Sep 28 '16 at 13:12
  • @jogo: Huh, I expected that this had been filed as an issue before, but did not find anything with a "German date" search in the rmarkdown issues. Good to know, thanks! Since yihui also suggests to escape the dot I guess I can mark my answer as the official one. ;) – dpprdan Sep 28 '16 at 13:43

1 Answers1

10

The problem is that pandoc converts a number followed by a dot at the beginning of the line to an ordered list, so in this case it renders "28. September 2016" as an ordered list that starts at 28 with the item "September 2016". The (probably) simplest way to remedy this is to escape the dot in r/rmarkdown.

**Date with escaped dot**

`r format(Sys.Date(), "%d\\. %B %Y")`

date with escaped dot

Update: If you want to use the German long date in the YAML header, use

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

i.e. single outer quotes and double inner quotes.

dpprdan
  • 1,727
  • 11
  • 24