robots@work: semiautomatic reports with r...
TRANSCRIPT
-
Robots@work:Semiautomatic Reports with R MarkdownuRos 2019 – 21.5.2019Max Grütter, Statistical Office of the Canton of Zurich
-
Statistical Office of the Canton of Zurich2
Source: Youtube.com, video produced by Kraftwerk
-
Statistical Office of the Canton of Zurich3
Our Corporate-Design Toolbox @ STAT ZH• Colors for R-graphics
zhpal
• Theme for ggplot2 graphics theme_stat
• Write data in formated Excel-tables statXLSX
• Reports & pdf documents statRmd
-
Statistical Office of the Canton of Zurich4
Our robots (resp. semiautomatic reports)
Quarterly Reports Cluster Booklet
Complete workflowin R Markdown
Reproducible
Available on Gitea
High-quality graphical and layout
concept
Dynamicallygenerated text
-
Statistical Office of the Canton of Zurich5
Example 1: The quarterly reports
-
Statistical Office of the Canton of Zurich6
Purposes of the quarterly reports
− Plausibility check of the data− Simple interpretation of data− Publication of the results
Tell our customers that we have new data!
-
Statistical Office of the Canton of Zurich7
The workflow
Icons by flaticon, rstudio, oracle, LogRocket, kisspng
-
Statistical Office of the Canton of Zurich8
The core element
Of a total of 6,949 sales in the last 12 months, 284 were transactions ofresidential land. This is the same as in the quarterly report 3/2018.
Of a total of 6,891 sales in the last 12 months, 284 were transactions ofresidential land. This is 3.4% less than in the quarterly report 2/2018.
-
Statistical Office of the Canton of Zurich9
The output
-
Statistical Office of the Canton of Zurich10
Example 2: The cluster booklet
-
Statistical Office of the Canton of Zurich11
The core element
+
Reproducible Analytical Pipeline
+
-
Statistical Office of the Canton of Zurich12
And what's behind it all now?
-
Statistical Office of the Canton of Zurich13
What do we need for the reports?
A R
md-
file
Latexengine:xelatex
YAML header
Sql chunks
R chunks
Text fragments
Setup the whole document
Load and precalculate the data
Computing indicators and graphs
Writing dynamic text parts
-
Statistical Office of the Canton of Zurich14
The YAML header
Use parameters for a dynamic document
Choose the right output format
Store all Latex in a separate file
Define title and author
-
Statistical Office of the Canton of Zurich15
What were and are our challenges?
− Sensitive interaction of R Studio and Latex− interaction of latex packages can be tedious− Layout can be controlled (and overridden) with different latex
packages− On different computers, the output may look different− Not all fonts (Windows fonts) are supported (If R on Linux)
-> solved: extrafont()
-
Statistical Office of the Canton of Zurich16
Plans and wishes for the future− Work in a global environment (e.g. on the Linux server)− Using dbplyr to utilize the computing power of the db− More reports− fully automatic reports− Introduce automatic data tests with abort criteria− Create a template for future reports
-
Statistical Office of the Canton of Zurich17
Summary− Semiautomatic reports with R Markdown are easy to produce− Also high quality designed reports are well realizable
thanks to Latex− Once (correctly) set up, you can create updated versions of
the report at any time without much effort.
− You should take some time to set up semiautomatic reports for the first time!
-
Statistical Office of the Canton of Zurich18
Keep moving and in touch
Mail: [email protected]: statistik.zh.chTwitter: @statistik_zh
Source: Youtube.com, video produced by Kraftwerk
-
Statistical Office of the Canton of Zurich19
Used PackagesR (only the core packages):− Tidyverse (dplyr, ggplot2, tidyr, forcats, stringr), Roracle, knitr,
magrittr, sf
Latex (miktex):− etoolbox, geometry, scrextend, afterpage, babel, LastPage,
transparent, hyphenat, fontawesome, footmisc, xcolor, tocloft, fancy, tocstyle, tikz, fancyhdr, array, tabu, sectsty, multicol, fontspec, inputenc,eso-pic
Foliennummer 1Foliennummer 2Our Corporate-Design Toolbox @ STAT ZH�Our robots (resp. semiautomatic reports)Foliennummer 5Purposes of the quarterly reportsThe workflowThe core elementThe outputFoliennummer 10The core elementFoliennummer 12What do we need for the reports?The YAML headerWhat were and are our challenges?Plans and wishes for the futureSummaryKeep moving and in touchUsed Packages