In an earlier post I wrote on how to use R to produce all kind of figures and tables for a LaTeX paper. This time, I will show, how to automate this process even more.
My work flow consists of a batch file, that runs my model, sends the results to R, produces my tables and figures and sends these to my paper: If I change my model, I just have to run this batch file, and the results in my paper are automatically adjusted. One smaller problem is that I often write in my text on a specific value from a table (for example, the minimum time used). Every time I change my model, I have to check these entries by hand (of course, I could use knitr, but that is on my list for the future and at the moment, I want to keep my R-files separate from my LaTeX files).
Here is a neat trick, to automate this process. Suppose I have calculated the reduction in time in my model and exported the results to R. In my paper I have the following sentence:
“As you can see in Table 1,in the scenario “Cruising” the reduction in driving time is 12.4%.”
In my R-script, I have the R-Code that produces this value or takes the value from my model results directly. Now I use some simple R-commands to produce a LaTeX file that can be included in my paper:
In my LaTeX-paper, I now just change the sentence to:
As you can see in Table 1,in the scenario
"Cruising" the reduction in driving time is
This produces the same sentence as before. However, if I change my model, the minimal reduction is changed and automatically adjusted.