是否可以在 R Markdown/knitr 中创建伪代码的代码块?
Is it possible to create a code block of pseudocode in R Markdown/knitr?
我试过使用反引号和波浪号,但它们需要语言。我只想要一个带高亮背景的格式化纯文本代码块。
使用 eval=FALSE
和 tidy=FALSE
直到到达关键字 if
,后续代码将在 .Rmd
文件和输出 PDF 中以颜色突出显示.不通过选项指定语言会删除背景突出显示输出中代码的功能。
```{r, eval=FALSE,tidy=FALSE}
loop through each species
loop through each measurement of the current species
if measurement ...
etc.
```
使用 tidy = FALSE
```{r, tidy=FALSE, eval=FALSE, highlight=FALSE }
pseudocode
```
编辑:添加高光,以防统一颜色
这里有一些示例代码可以很好地呈现 HTML。它还可以正确呈现为 Word 和 PDF。
---
title: "Untitled"
output: html_document
---
Here is some plain text.
Next, let's write some pseudo code. Note that you don't _have_ to specify a language if using plain backticks.
```
object <- [some kind of calculation]
```
If you set `eval = FALSE` you can get the highlighted background
```{r, eval = FALSE}
object <- [some kind of calculation]
Note that this; is not valid R code
```
You may find it interesting that your example works just fine for me.
```{r, eval=FALSE}
loop through each species
loop through each measurement of the current species
...
etc.
```
我试过使用反引号和波浪号,但它们需要语言。我只想要一个带高亮背景的格式化纯文本代码块。
使用 eval=FALSE
和 tidy=FALSE
直到到达关键字 if
,后续代码将在 .Rmd
文件和输出 PDF 中以颜色突出显示.不通过选项指定语言会删除背景突出显示输出中代码的功能。
```{r, eval=FALSE,tidy=FALSE}
loop through each species
loop through each measurement of the current species
if measurement ...
etc.
```
使用 tidy = FALSE
```{r, tidy=FALSE, eval=FALSE, highlight=FALSE }
pseudocode
```
编辑:添加高光,以防统一颜色
这里有一些示例代码可以很好地呈现 HTML。它还可以正确呈现为 Word 和 PDF。
---
title: "Untitled"
output: html_document
---
Here is some plain text.
Next, let's write some pseudo code. Note that you don't _have_ to specify a language if using plain backticks.
```
object <- [some kind of calculation]
```
If you set `eval = FALSE` you can get the highlighted background
```{r, eval = FALSE}
object <- [some kind of calculation]
Note that this; is not valid R code
```
You may find it interesting that your example works just fine for me.
```{r, eval=FALSE}
loop through each species
loop through each measurement of the current species
...
etc.
```