How to embed and escape R Markdown code in a R Markdown document

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:44:13

问题


I'm trying to write a memo on R Markdown syntax and as such I'd like to include in the document's output the R Markdown code and the output.

To be clear, I'd like the output to look something like:

~~~~~~~~~~~~~~~~~~
Including the following code chunk in the document:

```{r, eval=FALSE}
summary(cars)
```

will produce the following output:

summary(cars)

~~~~~~~~~~~~~~~~~~

I'm failing to escape the ``` and the {r, eval=FALSE}.


回答1:


Maybe if you evaluate this:

```{r comment=NA}
cat("```{r, eval=FALSE}\nsummary(cars)\n```")
```


来源:https://stackoverflow.com/questions/29509274/how-to-embed-and-escape-r-markdown-code-in-a-r-markdown-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!