3

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 
Community
  • 1
  • 1
RobertMyles
  • 2,673
  • 3
  • 30
  • 45

1 Answers1

4

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")`.
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Thanks Yihui. It was more for when I am writing drafts, because I may start a draft and then not actually finish it for a while, but I'd like the date to be the date it was finished on. – RobertMyles Feb 07 '17 at 11:23
  • 1
    Okay, I just wanted to point out the caveat (the permanent link can change after the date is changed). If you are aware of the potential issue, please feel free to use a dynamic date temporarily before you finish the post. – Yihui Xie Feb 07 '17 at 21:18