Search code examples
rlatexrstudiosweave

how do you programatically create sub sections in latex/sweave


I have a over 100 of applications and cpu and performance data for each application. I need to go through my data set and create cpu and memory charts for all these apps. Each app needs to have its own section in pdf.

Let's say, I have a application vector like this:

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

How would I programatically create subsection for each app and insert cpu and memory?

Output could be like this:

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

etc

I've tried this:

\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}

I get this error when I try to compile to 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

any ideas?


Solution

  • You are close, just put Sweave's

    <<results=tex>>=
    

    instead of (knitr's)

    <<results='asis'>>=
    

    Alternatively, use knitr. For that you might need to call Sweave2knitr() on the existing files.

    For reference, see Sweave manual, page 13, or knitr chunk options.