YAML current date in blogdown
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")`.
Markdown YAML date settings using functions that require library()
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:
Is there a way to extract the date information from the YAML header in Rmarkdown for use in an R chunk?
From outside the rmarkdown document, rmarkdown::yaml_front_matter()
should work well for you.
However, if you're talking about inside (within a chunk itself), then I think you should look into Parameterized RMarkdown documents; specifically, include a params:\n date: !r Sys.date()
, and elsewhere in your document use params$date
in R.
For example:
---
title: My Document
output: html_document
params:
date: !r Sys.Date()
---
## Header
Inline, today's date is `r params$date`.
```{r}
cat("In a code chunk, today's date is ", format(params$date, format = "%b %d, %Y"), "\n")
```
If you need to specific a specific date other than "today", you can change the value when you render it,
rmarkdown::render('foo.Rmd', params=list(date="2020-01-01"))
(Though in this example, "2020-01-01"
will not be reformatted properly within my example, since format
won't be getting an actual Date
-class object. Topic for a different day :-)
set date format for knitr document
Following the R Markdown Cookbook you could achieve your desired resulting via a custom knit_print
method. To add some flexibility you could add the date format as a parameter in the YAML header which e.g. allows to render the document with different date formats.
---
title: Custom knit_print for Dates
output: html_document
params:
date_format: '%d %m %Y'
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
knit_print.Date = function(x, ...) {
format(x, params$date_format)
}
registerS3method(
"knit_print", "Date", knit_print.Date,
envir = asNamespace("knitr")
)
```
```{r}
DATE <- as.Date(Sys.Date())
```
`r as.Date(Sys.Date())`
Get datetime during deploy in YAML file
I managed to solve my problem. First of all, I removed all the changes I did in YAML files.
and then I updated the only adf.content.json
"parameters": {
"baseTime": {
"type": "string",
"defaultValue": "[utcNow('u')]",
"metadata": {
"description": "Schedule will start one hour from this time."
}
}
}
and update the variable, I want to run 15min after the deploy
"variables": {
"startTime": "[dateTimeAdd(parameters('baseTime'), 'PT15M')]"
}
German long date in rmarkdown
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")`
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.
How to change the font color of title, author, date and make it bold in yaml of Rmarkdown?
One way is to use a latex code chunk in the title.
---
title: |
```{=latex}
\textcolor{red}{\textbf{PDF Document}}
```
author: "Sana"
output: pdf_document
---
Related Topics
How to Format a Number as Percentage in R
How to Use Facets With a Dual Y-Axis Ggplot
Replace Multiple Letters With Accents With Gsub
How to Extract Plot Axes' Ranges For a Ggplot2 Object
What Are Replacement Functions in R
What Ways Are There to Edit a Function in R
Rolling Mean (Moving Average) by Group/Id With Dplyr
Programming With Dplyr Using String as Input
Compute Mean and Standard Deviation by Group For Multiple Variables in a Data.Frame
Incomplete Final Line' Warning When Trying to Read a .Csv File into R
How to Tell What Is in One Vector and Not Another
Ggplot2 Two-Line Label With Expression
Subset Rows in a Data Frame Based on a Vector of Values
How to Subtract/Add Days From/To a Date
How to Convert Dataframe into Time Series
Subset Data to Contain Only Columns Whose Names Match a Condition