你如何在 knitr 中创建有组织的部分
how do you create organizned sections in knitr
我试图在 knitr 中包含部分,但我看到了一个奇怪的行为:
这是文件的标题:
title: "cpu usage document"
date: "October 29, 2015"
output:
pdf_document:
number_sections: yes
toc: yes
toc_depth: 2
highlight: zenburn
keep_tex: true
---
在块的一侧我有这样的东西:
cat("# cpu1 Bound \n")
print(ggplot output here)
cat("# memory1 Bound \n")
print(ggplot output here)
cat("# cpu2 Bound \n")
print(ggplot output)
cat("# memory2 Bound \n")
print(ggplot output)
当我编译 knitr 时
我看到了这样的东西。
1. cpu1 bound
ggplot chart
2.memory bound
3.cpu2 bound
4.memory2 bound
ggplot output for memory1
ggplot output for cpu2
ggplot output for memory2
我做错了什么?有没有更好的方法在 knitr 中创建部分?
使用正确的 Markdown — 不要使用 cat
,也不要使用 print
。
## cpu1 Bound
```{r}
ggplot output here
```
## memory1 Bound
```{r}
ggplot output here
```
## cpu2 Bound
```{r}
ggplot output here
```
# memory2 Bound
```{r}
ggplot output here
```
(另请注意,我使用了 2 级标题,因为 1 级标题通常对应于文档标题,因此只能在开头使用一次。)
我试图在 knitr 中包含部分,但我看到了一个奇怪的行为:
这是文件的标题:
title: "cpu usage document"
date: "October 29, 2015"
output:
pdf_document:
number_sections: yes
toc: yes
toc_depth: 2
highlight: zenburn
keep_tex: true
---
在块的一侧我有这样的东西:
cat("# cpu1 Bound \n")
print(ggplot output here)
cat("# memory1 Bound \n")
print(ggplot output here)
cat("# cpu2 Bound \n")
print(ggplot output)
cat("# memory2 Bound \n")
print(ggplot output)
当我编译 knitr 时
我看到了这样的东西。
1. cpu1 bound
ggplot chart
2.memory bound
3.cpu2 bound
4.memory2 bound
ggplot output for memory1
ggplot output for cpu2
ggplot output for memory2
我做错了什么?有没有更好的方法在 knitr 中创建部分?
使用正确的 Markdown — 不要使用 cat
,也不要使用 print
。
## cpu1 Bound
```{r}
ggplot output here
```
## memory1 Bound
```{r}
ggplot output here
```
## cpu2 Bound
```{r}
ggplot output here
```
# memory2 Bound
```{r}
ggplot output here
```
(另请注意,我使用了 2 级标题,因为 1 级标题通常对应于文档标题,因此只能在开头使用一次。)