R降价代码折叠不适用于bash和Python代码块

2024-05-29 05:27:23 发布

您现在位置:Python中文网/ 问答频道 /正文

R Markdown现在可以选择在.Rmd文档中自动show or hide code chunks。然而,这似乎只适用于R代码块。在

---
output: 
  html_document: 
    code_folding: hide
---

```{r}
print("This code chunk will be hidden")
```

```{r, engine='bash'}
echo "This code chunk will not be hidden"


```{r, engine='python'}
print "Will this code chunk be hidden?"
```

```{r}
system('uname -srv',intern=T)
sessionInfo()
```

Output

我能想出的唯一解决方案是将代码隐藏在空白选项卡后面

^{pr2}$

Blank Tab

有没有更好的解决方案可以对所有代码块进行代码折叠?在


Tags: 代码文档showcodebe解决方案thiswill
2条回答

你也可以在后期制作中修复它。我使用rmarkdown::render()(r3.4.1)和pandoc-1.17.2转换Rmd->;HTML。生成的HTML文件对不同的语言使用不同的CSS类,但只有<;pre>;类“sourceCode r”支持折叠。在

因此,只需将<;pre>;标记中的所有非“r”类更改为“r”:

perl -i -pe 's/<pre class="sourceCode [^r]+">/<pre class="sourceCode r">/' myfile.html

代码在块中的外观不会改变。在

也许R版本在这里起作用?对我来说,没有任何修改,您的代码可以按预期工作:

## R version 3.3.3 (2017-03-06)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: macOS Sierra 10.12.6

至于R演播室

^{pr2}$

enter image description here

当然,我改变了(从你最初的职位)

```{r, engine='bash'}
echo "This code chunk will not be hidden"

```{r, engine='bash'}
echo "This code chunk will not be hidden"
```

相关问题 更多 >

    热门问题