您如何以编程方式在 latex/sweave 中创建子部分

how do you programatically create sub sections in latex/sweave

我有超过 100 个应用程序和 cpu 每个应用程序的性能数据。我需要检查我的数据集并为所有这些应用程序创建 cpu 和内存图表。每个应用程序都需要在 pdf 中有自己的部分。

比方说,我有一个这样的应用向量:

app<-c("Web", "Farm1", "Farm2", "Pod1")

我如何以编程方式为每个应用程序创建小节并插入 cpu 和内存?

输出可能是这样的:

1. Webb
           cpu chart
           memory chart
2. Farm1
          cpu chart
          memory chart 

等等

我试过这个:

\documentclass{article}

\begin{document}
\title{applications cpu and memory}
\SweaveOpts{concordance=TRUE}
\tableofcontents

<<results='asis'>>=
   for (product in app){ 
    cat(paste("\section{",product,"}", sep="")) }
    @


    \end{document}

当我尝试编译为 pdf 时出现此错误:

Writing to file ddd.tex
Processing code chunks with options ...
Error in match.arg(options$results, c("verbatim", "tex", "hide")) : 
  'arg' should be one of "verbatim", "tex", "hide"
Calls: <Anonymous> -> SweaveParseOptions -> check -> match.arg
Execution halted

有什么想法吗?

你很接近,就把Sweave

<<results=tex>>=

而不是 (knitr 的)

<<results='asis'>>=

或者,使用 knitr。为此,您可能需要对现有文件调用 Sweave2knitr()

参考 Sweave manual, page 13, or knitr chunk options