r 代码块中的输出降价 [英] output markdown in r code chunk
问题描述
我有一个 R markdown 文件,我想从脚本本身输出 rmarkdown.例如,我将在 Rmd 文件中包含以下简单代码.
I have a R markdown file that I want to output rmarkdown from the script itself. For example, I would have the following simple code in an Rmd file.
---
title: "test"
author: "johndoe"
date: "September 5, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars}
paste("## This is a Heading in Code")
summary(cars)
```
我希望这是代码中的标题"在 rmarkdown 中呈现.R 脚本中有一个解决方案可以根据 http://rmarkdown.rstudio.com/r_notebook_format 生成降价.html.但我想弄清楚如何在 Rmarkdown 文件中做到这一点.任何帮助表示赞赏.谢谢.
I want "This is a Heading in Code" to render in rmarkdown. There is a solution in an R script to generate markdown as per http://rmarkdown.rstudio.com/r_notebook_format.html. But I am trying to figure out how to do this in a Rmarkdown file. Any help appreciated. Thanks.
推荐答案
为什么手动构建标题标记(在 Markdown 或 HTML 中)?在 pander
中尝试内联 R 表达式或一些辅助函数(以编程方式生成降价):
Why build the header markup (either in markdown or HTML) manually? Try inline R expressions or some helper functions in pander
(to generate markdown programatically):
---
title: "test"
author: "johndoe"
date: "September 5, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## `r 'This is a Heading in Code'`
```{r title, results='asis'}
library(pander)
pandoc.header("This is a Heading in Code", level = 2)
```
```{r cars, results='asis'}
summary(cars)
```
这篇关于r 代码块中的输出降价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!