Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new override argument to pass metadata #52

Merged
merged 4 commits into from Oct 12, 2023
Merged

feat: new override argument to pass metadata #52

merged 4 commits into from Oct 12, 2023

Conversation

mcanouil
Copy link
Contributor

@mcanouil mcanouil commented Aug 25, 2022

This PR add a new argument, namely override which takes a named list and pass it to quarto render --metadata key:value.

Fixes #49

quarto_render("notebook.Rmd", override = list(lang = "fr", echo = "false"))

Example:

---
format: html
lang: fr
title: "My Document"
author: "Norah Jones"
date: 5/22/2022
---

Something to check `lang` metadata: `{{< meta lang >}}`.

```{r}
1 + 1
```

Rendered:

quarto_render("index.qmd", override = list(lang = "es", echo = "false"))

image

quarto_render("index.qmd", override = list(lang = "en", echo = "false", eval = "false"))

image

@maelle
Copy link

maelle commented Aug 25, 2022

Cool! However when you render with fr and es, which is it still "author"/"published" and not their translation? it's not the actual lang option that's changed?

@mcanouil
Copy link
Contributor Author

mcanouil commented Aug 25, 2022

I am not sure to understand your question.
The HTML metadata is also changed (for the second example):

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

It really overrides any yaml option set in a document (did not try, but it should also overrides _quarto.yml yaml options.

@maelle
Copy link

maelle commented Aug 25, 2022

I mean that in French it should show "Auteur·rice", not the English version, so that option was not changed?

@mcanouil
Copy link
Contributor Author

Bad order in fact 😅
I'd did not take a screenshot of the default.

@maelle
Copy link

maelle commented Aug 25, 2022

aaah ok, thank you/merci !!

@jcolomb
Copy link

jcolomb commented Sep 9, 2022

Great addition.
will it also add metadata not present, or does it only override existing one ?
does it override the format metadata too?

PS would be cool if override would accept a yaml file (directly) instead of a list.

@mcanouil
Copy link
Contributor Author

mcanouil commented Sep 9, 2022

Override means override default or user defined yaml.

Regarding the possibility to pass a file, you can do that from Quarto CLI, but I don't see the rational for this to happen in R through the quarto package, it would be like simply avoiding CLI for some reason.

@jcolomb
Copy link

jcolomb commented Sep 10, 2022

isn't avoiding the cli the main reason to have a quarto package in R ?

all use case of using the quarto_render may want to add some options, no way to do that at the moment (for example, any reason you would use quarto_render(format = "revealjs") , you may want scrollable = true and you may want that inside a loop).

(note: I wanted that for using inside a loop going through all files, find a way to achieve it using projects: quarto-dev/quarto-cli#1433)

@mcanouil
Copy link
Contributor Author

mcanouil commented Sep 10, 2022

I was talking about the yaml file pass through R to Quarto.
You can do loops in bash/PowerShell/etc.

Being able to add/change yaml options using R syntax in quarto makes total sense, but at some points, if all the settings/etc. are just files why bother doing it from R?
From the rmarkdown point of view, it makes sense, because rmarkdown is an R package and requires R to render anything.
Quarto is language agnostics, so the same rational as for rmarkdown does not apply.

@salim-b
Copy link
Contributor

salim-b commented May 17, 2023

Maybe the new param should rather be named metadata to not unnecessarily deviate from the CLI. Other than that, very useful addition!

R/render.R Outdated Show resolved Hide resolved
@mcanouil
Copy link
Contributor Author

I am not even sure it's still valid since Quarto CLI had many changes since that time.

I think there is a lot to do and that needs to have a global plan to wrap Quarto CLI and ensure smooth update in the future.

@salim-b
Copy link
Contributor

salim-b commented May 18, 2023

Well, latest stable Quarto CLI still features the same --metadata parameter. But yeah, Quarto devs should really review this.

Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better to do using --metadata-file. We take the list of metadata, write to a temp file and pass it to quarto.

This will also be better considering quarto-dev/quarto-cli#6123

If that is ok, I'll implement it that way.

@mcanouil
Copy link
Contributor Author

mcanouil commented Oct 10, 2023

This PR and other are so old I don't even remember what they are about and the code itself.
Thus, feel free to modify, reimplement, close, or whatever.

(Same thing apply to the PR to add the ability to use/install extension which is obsolete as the extension commands changed since last year)

@cderv cderv merged commit 589c937 into quarto-dev:main Oct 12, 2023
14 checks passed
@mcanouil mcanouil deleted the fix-issue49 branch October 12, 2023 17:19
@cderv cderv self-assigned this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could one pass the "lang" parameter via quarto_render?
5 participants