I recently discover a R package, called liftr package. It allows the build of pdf document (and html files, but i didn’t test it) from a Rmarkdown file.
Fully integrated in RStudio, the R code is executed (and other code as well, I tried python) and results are displayed. You don’t even need to have LaTeX on your computer, since the document compilation take place in a docker image.
Good point, it is a minimal texlive installation so, it is a only 2.3 Go image (with the packages I needed, a little less than 2 Go without), more lighter than the almost 7 Go full texlive I use most of time.
It is well integrated in RStudio, so it provides an addin with 3 options:
- Containerize + render
- Purge docker image
Why containerize ? Because you can add you custom packages throught entries from the yaml header of the Rmd file. For example, the
sysdep entry allows you ton install debain packages, just by citing its name. You can also ask for specifique
cran packages, like
nycflights from the
cran entry. Using docker capabilities, liftr only rebuilt the layers you need so when you only edit the text, the process cna be very fast (althought it always render the code, which can take some time).
But I needed some refining like custom templates.
As student, I often have to produce reports in french, and even if there is no mandatory template, I created mine that I cna reused for reports and studies.
So I integrated it to liftr (see here1), because I liked how the liftr workflow (I had an idea like that several months ago). I think it can be a good example for Rmarkdown / pandoc capabilities (see 2).
With 2 colleagues, we have a school project about big amounts of data, treated with R or SAS. We have to provide a analysis report, a 15 minutes presentation and possibly a website. I hope we will can do it all with R using Rmarkdown tools like liftr, xaringan and blogdown.
Here is some aspects about liftr with my custom report template:
- all file are in one docs folder, with template folder and image folder
- all templates are loaded in /data/templates in the docker image
- all images are loaded in /images/ in the docker image and listed in process (easier to debug)
- most important informations of the title page are available from the yaml header (title, author, colors, fonts)
- several parameters are available:
- mainfont: custom main font (Linux Libertine O installed with apt by default)
- sansfont: custom sans font (Linux Biolinum O installed with apt by default)
- maincolor: choose main color for section title and title page ribbon
- secondcolor: for horizontal ribbon in the title page
- fontsize: 11pt ( show Rmarkdown option usage)
- lang: fr ( show Rmarkdown option usage)
- tocname: custom toc name (in France, with have 2 names depending of TOC position in the document)
- custom yml entries for title page:
- classname : project name
- formation: diploma major
- parcours: diploma minor
Cons / issues:
- multiple author list don’t work, needs to be on 1 line/string
- cls file needs the texlive-lang-french deb package, even for english document.
- some configurations need to be done in cls and tex file (moving things in title page, custom LoF and LoT titles), tweaking is not easy (2 separated files, latex macros, tikz) but can be done with generate and test.
- Makefile needs improvements (Rscript call to build the pdf), for now it just clean the working folder
- needs xelatex (provided by the docker image to work)
- include appendix or tex files
Shows some R/markdown features:
- python code execution
- MSBlue (M$ blue)
- MSLightBlue (lighter M$ blue)
- DarkColor( similar to DarkGrey)
- LightColor (similar to LightGrey)
- BaseColor (currently set to greenish color)
- TextColor (black)
- VertDepartementGeo (greenish color from my university department)
- jaune (yellow)
- bleu (blue)
- bleuciel (skyblue)
Custom colors are defined in etude.tex file (in 2 places, on for xetex/xelatex and the other for pdflatex).
So it was great for me, learning how to work with docker images, how to load data in the container (can’t use volumes). I get a better understanding about pandoc and LateX too, since the template I use was provided by the Computer Science Departement of Avignon University. I found it on Overleaf 3. It is pure Latex and provides a cls class and a tex file. So, sometimes ago, I tweaked it a little to use with pandoc, and I restarted from that. I improved it much, by adding more information from the yaml header, so there is less need to get in the LaTeX files.
If you just need more colors, a little knowledge about RGB and code is needed to set a new color. The hardest part is finding where make the change.