You can simply invoke Sweave in a loop as shown below.
# Create the template file, "test.Rnw" template <- "test.Rnw" cat(" \\documentclass{article} \\title{\\Sexpr{namelist[i]}} \\begin{document} \\maketitle \\end{document} ", file=template) # Parameters namelist <- c("Tom","Dick","Harry","John","Jacob") # Main loop: just compile the file, # it will use the current value of the loop variable "i". for(i in 1:length(namelist)) { Rnw_file <- paste("test_", i, ".Rnw", sep="") TeX_file <- paste("test_", i, ".tex", sep="") file.copy(template, Rnw_file) Sweave(Rnw_file) system(paste("pdflatex --interaction=nonstopmode", TeX_file)) }
source share