quarto-dev / quarto-r

R interface to quarto-cli
https://quarto-dev.github.io/quarto-r/
137 stars 18 forks source link

Setting title via metadata in `quarto_render` does not work #181

Open cderv opened 2 weeks ago

cderv commented 2 weeks ago

Could be related to quarto-dev/quarto-cli#8987

when I try to set title via metadata like so:

quarto::quarto_render("template.qmd", metadata = list(title = "Hahaha", author = "Whoever"))

the title set in metadata is not used in the header block or HTML header (nor emitted correctly via {{< meta title >}} in the body) when a title is set in the document header. When there is no title entry in the YAML header, the title set in metadata is used and does appear in the body.

Setting e.g. the author via metadata works correctly.

Originally posted by @petrbouchal in https://github.com/quarto-dev/quarto-cli/issues/8987#issuecomment-2116261659

cderv commented 2 weeks ago

the title set in metadata is not used in the header block or HTML header (nor emitted correctly via {{< meta title >}} in the body) when a title is set in the document header. When there is no title entry in the YAML header, the title set in metadata is used and does appear in the body.

I believe this is related to the order of YAML fields, and what Quarto R package is doing.

As we document in https://quarto-dev.github.io/quarto-r/reference/quarto_render.html quarto_render has two arguments:

--metadata-file will have lower precedence on YAML header content. This is expected by Pandoc (https://pandoc.org/MANUAL.html#option--metadata-file) and we document it as such too in our Reference pages image

So the behavior you see is expected, but really Quarto R package does not make that clear. 🤔

metadata= is currently a way to provide a R list of object to be converted internally to YAML, and not really passed content to -M option - because R objects can't be directly. -M or --metadata only allows boolean or string really.

Currently you need to do the following

quarto::quarto_render("template.qmd", metadata = list(author = "Whoever"), quarto_args = c("--metadata", "title=Hahaha"))

I'll see how I can make this easier in the R package function 🤔