-
DescriptionI have a document with sql and R code chunks and I would like to set different code chunk options for each language. Both Bing Copilot and meta.ai suggest using the execute function in the yaml header as below. While the document renders fine, the chunk options seemed to be ignored by knitr.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Before anything else, I really do strongly recommend that you don't rely on LLMs for Quarto information: they tend to use old crawls that happened before Quarto, and confuse Quarto and RMarkdown on a regular basis. |
Beta Was this translation helpful? Give feedback.
-
Absolutely Agree. It is always a multi-step process to try to get something reasonable and even then it may not work. In this case, it does not seem to but thought I would check for alternatives. Thanks
From: Carlos Scheidegger ***@***.***>
Date: Monday, May 13, 2024 at 4:36 PM
To: quarto-dev/quarto-cli ***@***.***>
Cc: Richard Ressler ***@***.***>, Author ***@***.***>
Subject: Re: [quarto-dev/quarto-cli] How do I set different chunk options for different language code chunks, e.g., R and SQL in a single document. (Discussion #9656)
External Email: Use caution with links and attachments.
Both Bing Copilot and meta.ai suggest using the execute function in the yaml header as below
Before anything else, I really do strongly recommend that you don't rely on LLMs for Quarto information: they tend to use old crawls that happened before Quarto, and confuse Quarto and RMarkdown on a regular basis.
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/quarto-dev/quarto-cli/discussions/9656*discussioncomment-9425790__;Iw!!IaT_gp1N!z8G3qLLyvmPGVhx5DRymIgmsdIl1GuchwGks1nUthScNEscEVrwyu_ACH3HyeoUHcb55U4LQdp2Ju7-kXvnQuTN8uPQ$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AOCMN3O73XHGW6HX466HAFLZCEP4BAVCNFSM6AAAAABHU3T3R6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TIMRVG44TA__;!!IaT_gp1N!z8G3qLLyvmPGVhx5DRymIgmsdIl1GuchwGks1nUthScNEscEVrwyu_ACH3HyeoUHcb55U4LQdp2Ju7-kXvnQE3ZWtI4$>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thank for the response. It works for echo true and false but not for fenced as it is not a logical. I used to set the default to fenced and then tried to just set it to TRUE for non-SQL engines. However the following fails if the default is set to fenced as above.
with error
|
Beta Was this translation helpful? Give feedback.
-
Using Options hooks seems the right way Just in Quarto context, making sure to not overwrite is important (discussed in #9656 (reply in thread)) as Quarto could use hooks for some options already and you don't want to overwrite those (🤔 I am thinking we should try to protect against that maybe... ) Using Options template is another feature that can be useful You could then use Example with what you needed above ---
title: test
knitr:
opts_chunk:
echo: fenced
---
```{r}
#| label: createData
#| message: false
library(DBI)
```
```{r}
knitr::opts_template$set(sqlopts = list(echo = FALSE, connection = "con"))
```
```{r}
#| label: make-connection
con <- dbConnect(RSQLite::SQLite(), dbname = ":memory:")
dbWriteTable(con, "mtcars", mtcars)
```
```{sql}
#| opts-label: sqlopts
SELECT * FROM mtcars WHERE cyl = 4
```
```{r}
mtcars[mtcars$cyl == 4,]
```
The SQL chunk won't show. This is really not Quarto specific - just some knitr features, adapted in Quarto context. |
Beta Was this translation helpful? Give feedback.
Better to look in the documentation rather than trust LLM.
See https://quarto.org/docs/computations/execution-options.html where executing options are described.
For short, the suggestion is completely wrong and there is currently no way (natively) to do what you want.
It might be possible using a LUA filter.
PS: when you reply by email, don't include the original message: everything is posted (emails are still obfuscated), thus your actual message is "hidden" amongst all the elements of an email.