Search code examples
rsweave

how do you loop over a global variable in Sweave


I have a big Sweave file with a variable called "specialty" near the top. The rest of this file is Latex and R, and uses this variable.

How can I loop over various values for "specialty"?

Two possibilities are:

  1. Make the file be one big loop (and convert the Latex parts to R).
  2. Write a script that copies the Sweave file, replace the value of "specialty", and run Sweave on each copy.

Can you comment on these ideas, or suggest better ones?


Solution

  • Could you state what you want your document to look like in the end? Clearly it has repetitive structures in it. In which case, Sweave may not be the best tool. You might instead want to consider using something like brew. See this blog post on the Learning R blog for an example of how this works.