Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

German long date in rmarkdown

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?

like image 921
dpprdan Avatar asked Sep 28 '16 13:09

dpprdan


People also ask

How do you enter a date in RMarkdown?

To format = , provide a character string (in quotes) that represents the current date format using the special “strptime” abbreviations below. For example, if your character dates are currently in the format “DD/MM/YYYY”, like “24/04/1968”, then you would use format = "%d/%m/%Y" to convert the values into dates.

Does RMarkdown use Pandoc?

A recent version of Pandoc (>= 1.12. 3) is required to use the rmarkdown package. RStudio also automatically includes this so you do not need to download Pandoc if you plan to use rmarkdown from the RStudio IDE. If not using the RStudio IDE, you'll need to install Pandoc for your platform.

What is knitr RMarkdown?

RMarkdown is an extension to markdown which includes the ability to embed code chunks and several other extensions useful for writing technical reports. The rmarkdown package extends the knitr package to, in one step, allow conversion between an RMarkdown file (.Rmd) into PDF, HTML, word document, amongst others.

How do you insert a line break in RMarkdown PDF?

Add Line Breaks in R Markdown To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .


1 Answers

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.

like image 173
dpprdan Avatar answered Sep 24 '22 05:09

dpprdan