I'd like to set date in YAML in R Markdown settings using following function:
paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")
but this code contains functions from 2 packages: timeperiodsR and lubridate, so it's necessary to prior use library(timeperiodsR) and library(lubridate).
How should code after date: look like, because the following is not working?
title: " "
date: '`r library(timeperiodsR) library(lubridate) paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'
Use ";" to indicate newline:
---
title: "mytitle"
date: '`r library(timeperiodsR); library(lubridate); paste(month(previous_month(part="start"),label=TRUE,locale=Sys.setlocale("LC_TIME", "English"),abbr=FALSE), year(previous_month(part="start")), sep=" ")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'
---
Or use base (no dependencies, one-liner):
---
title: "mytitle"
date: '`r format(seq(Sys.Date(), length = 2, by = "-1 months")[ 2 ], format = "%B %Y")`'
output:
html_document:
toc: true
toc_depth: 2
toc_float:
collapsed: false
smooth_scroll: false
fig_align: 'center'
---
Both give the below same output:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With