class: center, middle, inverse, title-slide # Academic writing using RMarkdown ## Books, reports, blogs, slides, … ### Sebastian Sauer ### FOM
DGPs 2018 --- class: inverse, center, middle # What is RMarkdown? <img src="https://www.rstudio.com/wp-content/uploads/2014/04/rmarkdown-200x232.png" width="200" height="232"> --- class: top, left # Markdown is not HTML ```html <ul class="nav-links"> <li><a href="/about/">About</a></li> <li><a href="/">Blog</a></li> <li><a href="/privacy/">Data privacy</a></li> </ul> </nav> </header> <main class="content" role="main"> <article class="article"> <span class="article-duration">40 min read</span> <h1 class="article-title">Bayesian modeling of populist party success in German federal elections - A notebook from the lab</h1> <span class="article-date">2018/08/25</span> <div class="article-content"> <p>Following up on an <a href="https://data-se.netlify.com/2017/10/10/afd-map/">earlier post</a>, we will model the voting success of the (most prominent) populist party, AfD, in the recent federal elections. This time, Bayesian modeling techniques will be used, drawing on the <a href="https://xcelab.net/rm/statistical-rethinking/">excellent textbook</a> my McElreath.</p> <p>Note that this post is rather a notebook of my thinking, doing, and erring. I’ve made no efforts to hide scaffolding. I think it will be confusing to the uniniate and the initiate as well …</p> <hr /> ``` --- # Markdown is not Latex ```tex \makeatletter \newenvironment{kframe}{% \medskip{} \setlength{\fboxsep}{.8em} \def\at@end@of@kframe{}% \ifinner\ifhmode% \def\at@end@of@kframe{\end{minipage}}% \begin{minipage}{\columnwidth}% \fi\fi% \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep \colorbox{shadecolor}{##1}\hskip-\fboxsep % There is no \\@totalrightmargin, so: \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}% \MakeFramed {\advance\hsize-\width \@totalleftmargin\z@ \linewidth\hsize \@setminipage}}% {\par\unskip\endMakeFramed% \at@end@of@kframe} \makeatother ``` --- # Last time I tried to tweak some details in my Latex document .center[ ![](imgs/latex-tweak.gif) ] --- # Markdown is simple markup .pull-left[ ```markdown # This is a title This is a sentence. Now a list begins: - no importance - again - repeat A numbered list: 1. first 2. second 3. third __bold__, _italic_, ~~strike through~~ ``` ] .pull-right[ # This is a title This is a sentence. Now a list begins: - no importance - again - repeat <br> A numbered list: 1. first 2. second 3. third __bold__, _italic_, ~~strike through~~ ] --- # Want some more? .pull-left[ ```markdown # Title level 1 ## Title level 2 Link: [my blog](https://data-se.netlify.com/) Citation: [@Xie2018] Image: ![my image](imgs/R-logo_small.png) ``` ] .pull_right[ # Title level 1 ## Title level 2 Link: [my blog](https://data-se.netlify.com/). Citation: (Xie & Allaire, 2018) Image: <img src="imgs/R-logo_small.png" width="40"> ] --- # I know you love your formulas ``` $$e^{\ln{e}} = e$$ ``` -- `$$e^{\ln{e}} = e$$` -- ``` $$\frac{\sum (\bar{x} - x_i)^2}{n-1}$$ ``` -- `$$\frac{\sum (\bar{x} - x_i)^2}{n-1}$$` -- ad nauseam Enter `\(\LaTeX\)` code in the same way. --- # Quickstart with Markdown .center[ ![](imgs/get-into-the-car.gif) ] --- # Markdown's Philosophy ## Keep. it. Simple. - No formating/styling. Content only - Pleasant to the eye - Portable --- # That's *R* Markdown (.Rmd) .center[ ![](imgs/rmd_flow-crop.png) ] --- # Simple R Markdown code ```` ``` Admire this curve: curve(dnorm(x), from = -2, to = 2) ``` ```` -- Admire this curve: <img src="rmd-writing_dgps2018_files/figure-html/unnamed-chunk-8-1.png" width="50%" style="display: block; margin: auto;" /> --- # Metadata is referenced in a separate container called YAML ``` --- ``` ``` author: Sebastian Sauer date: 2018-09-20 title: Some title output_format: pdf_document bibliography: cited_papers.bib csl: apa.csl ``` ``` --- ``` ``` Now normal text. ``` --- class: center, middle, inverse # What's RMarkdown good for? --- class: top, left # Websites/ Blogs ![](imgs/data-se-screenshot.png) --- # Reports ![](imgs/report-screenshot.png) --- # Books ![](imgs/modar.png) --- # Slides <br> <br> <br> <br> <br> .center[ 👌 ] --- # [Papaja](https://github.com/crsh/papaja): a template for APA papers ![](imgs/oom.png) --- # [yart](https://github.com/sebastiansauer/yart): a template for research reports ![](https://raw.githubusercontent.com/sebastiansauer/yart/master/docs/yart_screenshot.png) --- class: center, middle, inverse # Why should I use it? --- class: top, left # RMarkdown has more power <img src="imgs/git-push-force.gif" width="70%" style="display: block; margin: auto;" /> --- # But I love MS Word... Start writing with Word. Keep on writing. Sooner or later ... <img src="imgs/kid-waves.gif" width="80%" style="display: block; margin: auto;" /> Markdown does not choke at big documents. --- # Put code and text in the same document ``` The median reaction time was `r rt_md` sec. It was incredibly significant (p < `r. very_low_p`). We made science great again. ``` -- The median reaction time was 0.420 sec. It was incredibly significant (p < .001). We made science great again. ## 💖 no more copy-paste-errors. More reproducible --- #
Word's typography is so 80ies
Word : <img src="imgs/kerning_word.png" width="70%" style="display: block; margin: auto;" />
Latex (Markdown): <img src="imgs/kerning_latex.png" width="70%" style="display: block; margin: auto;" /> --- # Do cool stuff
--- # Interactive diagrams .center[ ![](imgs/gganimate.gif) ] --- class: middle, center, inverse # Sample project <img src="imgs/bookdown-logo.png" width="30%" style="display: block; margin: auto;" /> --- class: top, left # Book "Moderne Datenanalyse mit R" - 500 pages - ~200 figures - ~200 R listings Big thing. No choking, but long compilation. <img src="imgs/modar.png" width="50%" style="display: block; margin: auto;" /> --- # Chapter file ``` rmd_files: [ "index.Rmd", "01_Statistik_heute.Rmd", "02_Hallo_R.Rmd", "03_R_starten.Rmd", "04_Erstkontakt.Rmd", # "05_Datenstrukturen.Rmd", "06_Datenimport_und_export.Rmd", ... ] ``` --- # Config file ``` title: "Moderne Datenanalyse mit R" subtitle: "Entwurf" author: "Sebastian Sauer" lang: de-De documentclass: book classoption: a4paper fontsize: 11pt fontfamily: mathpazo ... ``` --- # Sample page <img src="imgs/modar-sample1.png" width="70%" style="display: block; margin: auto;" /> --- class: middle, center, inverse # Now what? --- # Get going with this book <img src="imgs/rmd-def-cover.jpg" width="30%" style="display: block; margin: auto;" /> --- # Or with this one <img src="imgs/bookdown-cover.jpg" width="30%" style="display: block; margin: auto;" /> --- # Disclaimer: There may be issues at times <img src="imgs/overhead-bin.gif" width="70%" style="display: block; margin: auto;" />
[StackOverflow](https://stackoverflow.com/) is your friend --- class: center, inverse, middle # Thank you Sebastian Sauer ####
[sebastiansauer](https://github.com/sebastiansauer) ####
<https://data-se.netlify.com/> ####
ssauer@posteo.de ####
[Sebastian Sauer](https://www.linkedin.com/in/dr-sebastian-sauer-4791762) ####
Get slides here: <http://data-se.netlify.com/slides/rmd-writing/rmd-writing_dgps2018.html#1> CC-BY .footnote[Built using R, RMarkdown, Xaringan. Inspiration from and thanks to [Yihui Xie](https://slides.yihui.name/2017-rmarkdown-UNL-Yihui-Xie.htm) and [Antoine Bichat](https://abichat.github.io/Slides/ScienceCommunicationSOTR/ScienceCommunicationSOTR.html), among others]