RobertMc RobertMc - 1 year ago 131
R Question

YAML current date in blogdown

There's a question here that deals with the formatting of dates for R Markdown. I'm using the blogdown package, and the answers there lead me to believe I could use:

'`r format(Sys.Date(), "%Y-%m-%d")`'
in the YAML front matter. Running
format(Sys.Date(), "%Y-%m-%d")
in the console gives me the date exactly as it would be in a regular Hugo blog post (i.e. "2017-02-03"), but this doesn't work with
serve_site()
(the post comes out as Jan 1 0001). Any ideas for how to get around this? Or is it necessary to use
date: "2017-02-03"
?

edit with doc example:

---
title: "new post"
author: Robert McDonnell
date: '`r format(Sys.Date(), "%Y-%m-%d")`'
categories:
- R
- yaml
tags:
- R
draft: true
---


The error returned from
build_site()
is:

ERROR: 2017/02/03 13:41:23 page.go:555: Failed to parse date '`r format(Sys.Date(), "%Y-%m-%d")`' in page post/x.html

Answer Source

This is a bug of blogdown and should be fixed now. Please reinstall the development version.

BTW, I don't think it is a good idea to use a dynamic date for blog posts, because the URL of a post may depend on its date (e.g. if you have set the format of permanent links to something like "/:year/:month/:day/:slug/"). You may have a fixed date in YAML, but a dynamic one in the body of your post like

This post was last updated on `r format(Sys.Date(), "%Y-%m-%d")`.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download