Open berkorbay opened 3 months ago
I realized it is mainly because when R chunks are included engine becomes knitr
. My interim solution is to use only R variables in the YAML.
As explained in the documentation, you cannot use two engines.
When there is an R code cell, then if no engine was specified, it means knitr
.
If only Python code cells, it means Jupyter.
knitr
engine is using reticulate
to run Python code.
Jupyter
engine has nothing by default to execute R code, so you need to install a Python module for that.
So set the engine you want to use to configure it.
Note that Quarto/Pandoc expect the metadata YAML block to be the first thing in the document (even if Pandoc allows multiple YAML block that are then merged together).
Also note that title is used for several things that occur early in the process.
To me there is no bug here.
Side question: why changing the metadata using computational parameters while you can directly change the metadata in the CLI? (See quarto render --help
)
I do not want to use two engines. But I would expect the parametric YAML behavior to stay the same because the engine switch is automatic. knitr
breaks python manipulation of YAML as shown in the MWE. metadata block is the first thing in the YAML, defined with python.
It is not actually a bug, but an undesired consequence of automatic engine switching. But I had only two options when reporting an issue 🙃
Side question: why changing the metadata using computational parameters while you can directly change the metadata in the CLI? (See
quarto render --help
)
My current settings and habits are different but I'll keep it in mind. I did not think it would be possible to change title from the CLI.
As answered, set the engine yourself: engine: whatever
Quarto only uses knitr
/reticulate
and has basically no control on them.
Also, the issue is that "Black" and other Python formatter don't want to make exception for #|
comment syntax, which means when you format your code cell it becomes # |
. Since formatters did not want to handle that, Quarto allowed it for Jupyter engine but knitr
does not know that.
I also highly suggest you keep the YAML block as the first thing in your document otherwise you'll lose auto-completion from various editors such as VSCode, VIM, and RStudio.
Input | Output |
---|---|
````qmd --- author: "The Author" format: pdf: toc: false number-sections: false execute: echo: false warning: false message: false engine: knitr --- ```{python} #| tags: [parameters] param1 = "aa" param2 = f"bb" ``` ```{python} #| output: asis print( f""" --- title: "Some title ({param1},{param2})" --- """ ) ``` ```{r} library(reticulate) ``` ```` |
Ah, I did not know a space between "#" and "|" would make such a difference. 💡 Then it solves my issue.
I’m reopening as there might be something that could be done related to # |
on Quarto/knitr
.
Also, the issue is that "Black" and other Python formatter don't want to make exception for #| comment syntax, which means when you format your code cell it becomes # |. Since formatters did not want to handle that, Quarto allowed it for Jupyter engine but knitr does not know that.
If we need to allow this for knitr engine in Quarto context, I think we can do that. but I did not know we supported # |
for Jupyter engine in the first place.
It was done because Python formater such as Black would break the cell every time if it was not supported.
The PR to allow #|
was dismissed (if I recall it was even before Quarto first release)
Bug description
I was preparing a parametric document where title changes with respect to some parameters. I was able to do so with only python code blocks. But when I add an R code block, regardless of the position, the outcome is not desirable. It just shows the yaml as a simple code block, not actual title/subtitle etc.
Steps to reproduce
author: "The Author" format: pdf: toc: false number-sections: false execute: echo: false warning: false message: false