我可以合并连续的代码块的代码,而不会在rmarkDown html_document中回荡
写入rmarkDown html_document
我经常有连续的代码块,但没有输出。 当这种情况发生时,就像当
- eval = false
- 结果=“隐藏”
时,我希望代码块“合并”。 我知道ref.label =“”
,它可以通过它来完成,但它会使块标签变得非常复杂/重。
是否有一些JavaScript,CSS,选项魔术可以帮助我实现自己想要的东西?
示例:
---
title: "Test"
date: '`r Sys.Date()`'
output: html_document
---
# Title 1
Some text
```{r, echo = TRUE, eval = FALSE}
1 + 1 # eval = FALSE so no output
```
```{r, echo = TRUE, results = "hide"}
1 + 2 # results hidden so no output
```
```{r, echo = TRUE}
1 + 3
```
Some other text
```{r, echo = TRUE, eval = FALSE}
1 + 4 # eval = FALSE so no output but text follows
```
Some other text
```{r, echo = TRUE}
1 + 4
```
输出
When writting rmarkdown html_document
I often have successive code chunks that are displayed but have no outputs.
When this happen, like when
- eval = FALSE
- results = "hidden"
I would like the code chunks to be "merged".
I know about ref.label = ""
and it could be done with it but it would makes chunk label to be extremely complex/heavy.
Is there some javascript, css, option magic to help me achieving what I'd like ?
example:
---
title: "Test"
date: '`r Sys.Date()`'
output: html_document
---
# Title 1
Some text
```{r, echo = TRUE, eval = FALSE}
1 + 1 # eval = FALSE so no output
```
```{r, echo = TRUE, results = "hide"}
1 + 2 # results hidden so no output
```
```{r, echo = TRUE}
1 + 3
```
Some other text
```{r, echo = TRUE, eval = FALSE}
1 + 4 # eval = FALSE so no output but text follows
```
Some other text
```{r, echo = TRUE}
1 + 4
```
output
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是使用 lua filter 合并代码块:
在哪里:
Merge-code-blocks.lua
包含结果文档:
set
code_block_sep ='\ n'
如果您不喜欢将块分开的空白线。这种方法的优点是它不是针对HTML的特定,即使使用PDF或单词输出也将继续使用。
One approach is to use a Lua filter to merge the code blocks:
where
merge-code-blocks.lua
containsResulting document:
Set
code_block_sep = '\n'
if you don't like the blank line separating the blocks.The advantage of this approach is that it is not specific to HTML and will continue to work even with PDF or Word output.
如果您需要的只是默认的HTML输出,那么您可以使用小型CSS攻击来获取所需的东西。它可以直接移动任何代码块,然后再向上移动1EM,卸下顶部边框并防止弯道被舍入。这给出了被合并的细胞的视觉效果。
必要的片段可以放置在文档中的任何地方。
If all you need is the default HTML output, then you can use a small CSS hack to get what you want. It moves any code block directly following another upwards by 1em, removes the top border and prevents corners from being rounded. This gives the visual effect of the cells being merged.
The necessary snippet can be placed anywhere in the document.