Rmarkdown的render()+ knitr的spin():如何混合代码块和嵌套项目 [英] Rmarkdown's render() + knitr's spin(): How to mix code blocks and nested items

查看:139
本文介绍了Rmarkdown的render()+ knitr的spin():如何混合代码块和嵌套项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rmarkdown的函数render()knitr的函数spin()R-脚本生成html和pdf笔记本.有时我使用嵌套列表,并将它们与代码块混合.这是使用rmarkdownknitr块选项的示例.

I'm generating html- and pdf-notebooks from R-scripts using rmarkdown's function render() and knitr's function spin(). Sometimes I use nested lists and mix them with code blocks. Here is an example using rmarkdown and knitr chunk options.

#' (1) This is normal text.
#'    (a) This is normal text but indented.
#+ echo = TRUE, eval = TRUE 
print("This is code")
#'    (b) This is supposed to be normal text with the same
#'        indentation as (a). However, it will be formatted as code.
#'        By this I mean that e.g. in a pdf-notebook it will be 
#'        correctly indented but the font will be the same font as 
#'        the code.

但是,列表项(a)之后的代码后面的所有内容也会被标记为代码(例如(b)).但是我要实现的是将(b)标记为普通文本,并使用与(a)相同的缩进.可以这样做吗?

However, everything that follows the code after list item (a) will be marked up as code as well (e.g. (b)). But what I want to achieve is to have (b) marked up as normal text and use the same indentation as (a). Is it possible to do this?

推荐答案

有一个内部块选项indent,可以将缩进添加到块输出中.您可以指定四个空格,例如

There is an internal chunk option indent that can add indentation to the chunk output. In your case, you can specify four spaces, e.g.

#+ echo = TRUE, eval = TRUE, indent = '    '

这篇关于Rmarkdown的render()+ knitr的spin():如何混合代码块和嵌套项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆