(I expect the answer is straightforward, but haven't been able to figure it out yet)
Every week I need to create a series of reports in PDFs, generated through knitr (using latex). Every report is identical in structure (the names and number of variables varies, but how they are processed is similar). What I want to be able to do is to create a function that something works like this:
createReport <- function(xmlfile, Rnwfile) {
ff <- parse xmlfile
extract relevant data from ff
calculate stats and generate tables and figures
call knitr such that the correct variable names, stats, etc are fed into the Rnw file
knit into a pdf file
save the pdf file on disc
}
(It would also be fine to calculate all the stats etc inside the Rnw-file.)
This way I can simply call createReport(datafile.xml, report.Rnw) for a given datafile.xml, and the appropriate PDF will be generated. How can this be done?
(NOTE: my question is about how to call knitr in a loop/from a function such that it will process the correct files and correct variables. I do already have a working latex/knitr script for a given dataset, but that has the name of the particular xmlfile and its variables hard coded inside it)