【问题标题】:how do you create organizned sections in knitr你如何在 knitr 中创建有组织的部分
【发布时间】:2015-10-29 16:32:57
【问题描述】:

我正在尝试在 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 中创建部分?

【问题讨论】:

  • 你希望你的输出是什么样子的?为什么要在cat 中添加标题?
  • 输出应该在每个标题下,应该有对应的ggplot。

标签: r markdown knitr


【解决方案1】:

使用正确的 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 级标题通常对应于文档标题,因此应该只在开头使用一次。)

【讨论】:

  • 我必须使用 cat 和 print,否则它对我不起作用,我需要关闭 cmets 等。
  • 我尝试了你的建议,但同样的行为对我不起作用
  • @user1471980 那么完全不清楚您要做什么。我的回答解决了您在问题下的评论所提出的确切问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-23
  • 2011-05-13
  • 2011-08-21
  • 1970-01-01
  • 2010-10-25
  • 2019-11-27
  • 2017-10-28
相关资源
最近更新 更多