remedy icon indicating copy to clipboard operation
remedy copied to clipboard

Feature request: rmarkdown verbatim chunk / inline

Open njtierney opened this issue 6 years ago • 2 comments

I'm frustrated when I want to show an rmarkdown chunk inside a rmarkdown document - in github, you can use four backticks and get the following:

```{r chunk-name, fig.align = "center"}
```

But this does not work for rmarkdown - @gadenbuie recently kindly reminded me of the trick from Yihui on how to shoe a verbatim chode chunk or inline E Expression

Describe the solution you'd like I'd love for verbatim to have two options:

  • "Show verbatim code chunk", and
  • "Show verbatim inline R expression"

Describe alternatives you've considered

At the moment the alternative is for me to remember this in my head, which I don't, and I find it hard to have a clear conceptual framework to remember that

`r ''`

will break knitr's chunk parser and allow me to show the thing I want.

Additional context

I think that's about it - just, in general, thanks for writing this super nifty package!

njtierney avatar Jun 20 '19 01:06 njtierney

I have recently tried this in {details} and {texPreview} and it seems to not be compatible with something in RStudio IDE. The play icon disappears in chunks that come after the four tick chunk, until I put in another four tick chunk.

image

and then when trying to run the chunk without a play icon I get an error in the output console


Error: attempt to use zero-length variable name
> knitr::kable(head(iris),format = 'latex',booktabs = TRUE)

\begin{tabular}{rrrrl}
\toprule
Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\
\midrule
5.1 & 3.5 & 1.4 & 0.2 & setosa\\
4.9 & 3.0 & 1.4 & 0.2 & setosa\\
4.7 & 3.2 & 1.3 & 0.2 & setosa\\
4.6 & 3.1 & 1.5 & 0.2 & setosa\\
5.0 & 3.6 & 1.4 & 0.2 & setosa\\
\addlinespace
5.4 & 3.9 & 1.7 & 0.4 & setosa\\
\bottomrule
\end{tabular}
> ```
Error: attempt to use zero-length variable name

yonicd avatar Jan 12 '20 15:01 yonicd

FYI current dev version of knitr introduces a new verbatim engine to facilitate this

Writing this (mind the number of bacticks to nest chunks)

````{verbatim, lang = "markdown"}
```{r chunk-name, fig.align = "center"}
```
````

will produce

````markdown
```{r chunk-name, fig.align = "center"}
```
````

cderv avatar Nov 17 '21 15:11 cderv