-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
Authentic usage of <<blah>>
in R code can't be knitted
#2360
Comments
Here's the new glue vignette where I would love to use this example function throughout (and the delimiters myglue <- function(..., .envir = parent.frame()) {
glue(..., .open = "<<", .close = ">>", .envir = .envir)
} https://glue.tidyverse.org/dev/articles/wrappers.html Update: I changed the example while writing that vignette and the new one doesn't ever have text like |
This was also reported by an epoxy user: gadenbuie/epoxy#127 Here's another minimal reprex showing that this issue impacts other knitr engines. ---
output: github_document
---
```{verbatim}
<<x>>
<<y>>
<<z>> other <<a>>
```
```{verbatim}
.<<x>>
``` When the above document is rendered, lines that start with ``` default
```
``` default
.<<x>>
``` |
I just applied a minimal fix so that knitr will ignore The documentation at https://bookdown.org/yihui/rmarkdown-cookbook/reuse-chunks.html was wrong and I just corrected. Perhaps originally (in 2013?) I wanted to make it work that way, but decided later that |
Thanks @yihui!
Personally, I would take advantage of this option if it existed to automatically disable the feature in chunks where |
I gave a 👍 above, but want to express my strong support for making it possible to just turn this feature off. Shall I open a new issue for that? |
No need to open a new issue. I'll add a chunk option to make it possible to turn off this feature. Thanks! |
I just added the chunk option |
Thanks @yihui! That sounds really useful. I will take the next opportunity I get to take the new option out for a spin. |
This is distilled from a Slack conversation with @cderv where we figured out what was going on.
I'm writing a new vignette for glue about how to write a wrapper around
glue::glue()
. A good example is if you want to create aglue()
variant that changes the delimiters, probably because the text you're working with has a legitimate use of{
and}
:<<
and>>
are the most common choice here, because they are so strongly associated with templating.The problem is that knitr's own templating often captures
<<blah>>
and modifies/removes that, breaking the code. I'm talking about this: https://bookdown.org/yihui/rmarkdown-cookbook/reuse-chunks.html.Consider this
.Rmd
document. The R code defines a string that could be used withmyglue()
(defined above) to produce the code for an R function definition:Running this code interactively produces:
But knitting this document results in:
The line containing
<<BODY>>
has gone missing! Because it matches this regex:"^\\s*<<(.+)>>\\s*$"
.Putting it all together, interactive execution of some code looks like this:
But knitting that same code produces:
A few thoughts:
<<BODY>>
in my example should be protected from knitr's templating because it occurs inside a string.<<<
and>>>
but that matches the regex too. There is no amount of brackets that will work.(This is really neither here nor there but the link above says that "The marker
<<label>>
does not have to be on a separate line. It can be embedded anywhere in a code chunk." This seems to be not be true any more, based on the regex and from the fact that<<NAME>>
is not a problem in my example, only<<BODY>>
, which appears on its own line.)The text was updated successfully, but these errors were encountered: