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
Option to show chunk options in output #1688
Comments
|
Yes, I admit it is awkward, and it has been bothering myself (but only mildly). Do you have time to improve https://github.com/yihui/knitr-examples/blob/master/062-chunk-wrapper.Rmd? |
|
Not sure this is an improvement on the solution you showed, but here's an alternative approach: # option 2: chunk option 'echo_opts'
hook_chunk = knit_hooks$get('chunk')
knit_hooks$set(chunk = function(x, options) {
if (!is.null(options$echo_opts)) {
return(paste0("```` ```{r ", options$params.src, "} ````", x, "```` ``` ````"))
} else {
return(hook_chunk(x, options)) # pass to default hook
}
}) |
|
Unless you want to actually evaluate the code chunk, I would put everything in a single code block: the chunk header, the code, and footer (all inside four backticks). Anyway, it seems you have understood the method. I'm not particularly interested in providing built-in support for this (it will require more thinking, e.g. code chunks may be indented, and I don't have time for this task). |
|
Hi- wanted to share the Quarto syntax for this: So instead of: You would use: |
|
Thanks @apreshill ! This is interesting, I wasn't aware I guess this works too ````r
```{{r setup, echo=TRUE}}
library(tidyverse)
```
````This is done in Quarto by a Lua filter. So we could bring this syntax to rmarkdown pretty easily. The filter would just need to be added to all type of formats. It works this way:
I guess you find it to be an easier syntax, aren't you ? It is quite nice. Side note on the result: ````{.markdown}
```{{r setup, echo=TRUE}}
library(tidyverse)
```
```` |
It looks good to me. A PR will be great.
I don't have a strong preference, but I always set the language to |
|
@ulyngs current dev version of knitr supports a new You can write to output the content of the verbatim chunk in a fenced code block I believe this solves you initially need, isn't it ? |
|
Hip hooray!!!!! :D |
|
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |


It's often important to be able to display a code chunk in the output where the reader is also able to see the chunk options.
At the moment, one has to do this rather awkwardly with something like:
Which outputs
It would be fantastically useful if something like
had the same effect.
The text was updated successfully, but these errors were encountered: