-
Notifications
You must be signed in to change notification settings - Fork 331
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
Conditional content that should not be rendered produces error #11724
Comments
Using
See option documentation: https://yihui.org/knitr/options/#package-options
What you are looking for is ---
title: "test"
format: pdf
---
Hello world
::: {.content-visible when-format="html"}
```{r}
#| eval: !expr knitr::is_html_output()
vembedr::embed_url("https://youtu.be/_AeywguOA0o")
```
:::
You could also just use an if clause on the cell ---
title: "test"
format: pdf
---
Hello world
::: {.content-visible when-format="html"}
```{r}
#| echo: false
if (knitr::is_html_output()) {
vembedr::embed_url("https://youtu.be/_AeywguOA0o")
}
```
:::
Note about using vembedr in Quarto - we have a video shortcode (https://quarto.org/docs/authoring/videos.html) that should do the same and will avoid running R for this. Hope it helps |
@cderv Thank you very much for that very helpful response. I am still a bit confused why the |
We document
It is meant to be use when code needs to be run but just be sure to hide anything in the output format. Hope it is clearer. |
Bug description
When rendering to pdf, neither using
::: {.content-visible when-format="html"}
nor using the chunk optionsinclude=knitr::is_html_output()
andecho = false
avoids an error about the fact that the code chunk, if rendered, would produce html output.Steps to reproduce
Here is an example where the code block uses the vembedr package. Rendering the quarto document
Expected behavior
The code block should be ignored for the pdf output
Actual behavior
An error:
Your environment
Quarto check output
Quarto 1.6.39
[✓] Checking environment information...
Quarto cache location: /home/gustav/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.4.0: OK
Dart Sass version 1.70.0: OK
Deno version 1.46.3: OK
Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.6.39
Path: /opt/quarto/bin
[✓] Checking tools....................OK
TinyTeX: v2024.12
Chromium: (not installed)
[✓] Checking LaTeX....................OK
Using: TinyTex
Path: /home/gustav/.TinyTeX/bin/x86_64-linux
Version: 2024
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK
Version: 3.12.3
Path: /usr/bin/python3
Jupyter: (None)
[✓] Checking R installation...........OK
Version: 4.4.2
Path: /usr/lib/R
LibPaths:
- /home/gustav/R/x86_64-pc-linux-gnu-library/4.4
- /usr/local/lib/R/site-library
- /usr/lib/R/site-library
- /usr/lib/R/library
knitr: 1.49
rmarkdown: 2.29
[✓] Checking Knitr engine render......OK
The text was updated successfully, but these errors were encountered: