How can I use inline code in a quarto document?

In my YAML Header I try this for date:

date: "`!expr format(Sys.time(), '%B %d, %Y')`"
date-format: dddd, D MMM YYYY
lang: de

But if I render I receive an error message:

Invalid Date

Did I use !expr in the correct way?

I found the answer in the Quarto documentation:

date: today

will help in the specific language format.

But how can i use an inline code with a variable in a markdown text within a quarto file with VS Code?

Thank you very much.

Sebastian

By a process of trial, error, and trawling through the Quarto documentation, I use the following at the top of my Quarto documents:

---
title: "This is the title"
description: This is the description
author: "A Person, B Another, C Someone"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
date-format: "D MMMM YYYY"
bibliography: bibliography.bib

I had not used the !expr version in the YAML header, so it might work in some other way. TAML syntax is quite picky...

Stephen

!expr is something valid with R yaml package when YAML is parsed with R. This syntax is working in R Markdown YAML header because rmarkdown is just R. But in Quarto it will work only for R document with YAML code chunk configuration (Quarto – Using R)

Inside YAML header of Qmd document, Quarto offers some keywords / alias and config to do the same, like date: today you found. Everything is here: Quarto – Quarto Dates and Date Formatting

If you mean like `r variable` syntax from knitr, you can do that in Qmd document using R too. There is no such inline syntax for Python as of now.

Quarto has also a mechanism for variables defined in YAML file - see Quarto – Variables

Hope it helps

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.