如何用空代码块创建 R markdown?
How to create R markdown with empty code chunk?
如何在 R markdown 中添加空代码块?我找到了几个选项来操纵 html 以提供更多的白色 space。但我想在众所周知的灰色代码框中显示一些空行,以指示 space 进行分配。
---
title: "Untitled"
author: "Author"
output: html_document
---
## R Markdown
```{r cars}
summary(cars)
```
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
```
一个 hacky 的方式......快到了:
```{r, code="'\n\n\n\n'", results=F}
```
使用 results = 'asis'
并依赖 chunck HTML 的可能解决方案 class:
```{r, results='asis', echo=F}
cat(
'<pre class="r">
<code class = "hlsj"> <span class="hljs-string"> <br> <br> </span> </code>
</pre>
')
```
只需添加<br>
以增加行数。
似乎没有办法让 knitr 将一个完全空的块识别为一个块。无论块选项如何,它总是会忽略它。
您必须插入一些内容才能呈现,例如评论。所以你可以在两个注释之间放置空行:
---
output: html_document
---
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
# Insert code here
# End
```
或者使用 strip.white=FALSE
块选项,我们可以使用单个注释行,但奇怪的是,这只适用于前导空格,而不适用于尾随空格:
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(strip.white = FALSE)
```
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
# Insert code above
```
如何在 R markdown 中添加空代码块?我找到了几个选项来操纵 html 以提供更多的白色 space。但我想在众所周知的灰色代码框中显示一些空行,以指示 space 进行分配。
---
title: "Untitled"
author: "Author"
output: html_document
---
## R Markdown
```{r cars}
summary(cars)
```
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
```
一个 hacky 的方式......快到了:
```{r, code="'\n\n\n\n'", results=F}
```
使用 results = 'asis'
并依赖 chunck HTML 的可能解决方案 class:
```{r, results='asis', echo=F}
cat(
'<pre class="r">
<code class = "hlsj"> <span class="hljs-string"> <br> <br> </span> </code>
</pre>
')
```
只需添加<br>
以增加行数。
似乎没有办法让 knitr 将一个完全空的块识别为一个块。无论块选项如何,它总是会忽略它。
您必须插入一些内容才能呈现,例如评论。所以你可以在两个注释之间放置空行:
---
output: html_document
---
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
# Insert code here
# End
```
或者使用 strip.white=FALSE
块选项,我们可以使用单个注释行,但奇怪的是,这只适用于前导空格,而不适用于尾随空格:
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(strip.white = FALSE)
```
## Homework
Please calculate the mean of the `speed` variable in `cars`.
```{r}
# Insert code above
```