In [1] I discussed a small script that exported GAMS data to R for plotting. Here I expand on that and show how we can use R Markdown [2] to generate documents that contain GAMS data and results. Here we have just a small example with just a parameter. But it is easy to see that this can also be used with larger models, where we have a document built around more complex model results.
R Markdown can handle as input text, R code, R graphics and LaTeX math (among others). Output can be HTML, PDF (via LaTeX), and DOCX (MS Word).
Here is my example:
$ontext |
This GAMS file has three parts:
- GAMS code to generate some data and to execute the R script
- R code to run the R Markdown process
- R Markdown code
Notes
- pandoc is a document translation system used by markdown. It comes with RStudio. That is the version I am using here.
- The output type is determined by the extension specified in doc_out.
- rmarkdown::render is the workhorse of the document creation process.
- After generating the document, it will be opened by shellexecute.
The LaTeX/pdf output looks like:
The advantage of this setup is that we can produce good looking reports basically automatically. Just run the GAMS model and get a report with the results.
References
- GAMS + R scripting, http://yetanothermathprogrammingconsultant.blogspot.com/2020/12/gams-r-scripting.html
- Yihui Xie and J.J. Allaire and Garrett Grolemund (2018). R Markdown: The Definitive Guide. Chapman and Hall/CRC.