-
Notifications
You must be signed in to change notification settings - Fork 26
Description
I'm very grateful for the qmd_to_r_script
function in quarto, and I'd love to have similar features for the other languages quarto supports natively. However, I've reverted to using knitr::purl()
because of a few issues:
qmd_to_r_script
does not respecteval=F
options. Code from chunks that are not evaluated should be printed in the script file, but should be commented out. This is useful for showing e.g. basic code patterns that don't have necessary arguments, but also for code that shouldn't be evaluated because of e.g. API key requirements or long compute times.qmd_to_r_script
needs to have some option to exclude the chunk from the script. For instance, I use thecountdown
package to add timers to my slides for hands-on activities, but I don't need that cluttering up the R script. Similarly, I use things likeemo::ji()
functions -- adding that to the R script would be pointless. I'm not sure what the chunk option should be -- in_script? purl? -- but this is an important feature, particularly for slides.- It would be helpful if
qmd_to_r_script
would include a comment with the chunk name (if it has one), to help someone connect the code to the document and keep their place in the script.
Just as a reprex, I created a sample.qmd
file with the following contents:
---
title: "Untitled"
format: html
---
## Code
You can embed code like this:
```{r}
1 + 1
```
## Eval=F behavior
Scripts should respect eval=F as a chunk option and comment out that code (but it should be present)
```{r this-chunk-shouldnt-evaluate, eval=F}
2+2
```
## Slide fanciness
If I have some sort of package that decorates the slide, I might include some code to do something that I don't need to keep in my script.
```{r dont-include-in-script, purl=F}
print("Fancy stuff")
```
Here is the output from knitr::purl
:
## ---------------------------------------------------------------------
1 + 1
## ----this-chunk-shouldnt-evaluate, eval=F-----------------------------
# 2+2
Notice that the last chunk isn't included, and the 2nd chunk is present but commented out.
Here is the comparable output from qmd_to_r_script()
:
#' ---
#' title: Untitled
#' format: revealjs
#' editor: visual
#' ---
#'
1 + 1
2+2
print("Fancy stuff")
I appreciate that the chunk header is replicated -- that's a nice feature. But, you see that 2+2
is not commented out, and print("Fancy stuff")
is present (and there's no way to turn it off that I could find).
My hope is that these are relatively simple features to fix -- they seem like they shouldn't be too terrible.
Thanks!