+ - 0:00:00
Notes for current slide
Notes for next slide

Academic writing using RMarkdown

Books, reports, blogs, slides, …

Sebastian Sauer

FOM
DGPs 2018

1 / 37

What is RMarkdown?

2 / 37

Markdown is not 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 />
3 / 37

Markdown is not Latex

\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
4 / 37

Last time I tried to tweak some details in my Latex document

5 / 37

Markdown is simple markup

# 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~~

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

6 / 37

Want some more?

# Title level 1
## Title level 2
Link: [my blog](https://data-se.netlify.com/)
Citation: [@Xie2018]
Image: ![my image](imgs/R-logo_small.png)

Title level 1

Title level 2

Link: my blog.

Citation: (Xie & Allaire, 2018)

Image:

7 / 37

I know you love your formulas

$$e^{\ln{e}} = e$$
8 / 37

I know you love your formulas

$$e^{\ln{e}} = e$$

elne=e

8 / 37

I know you love your formulas

$$e^{\ln{e}} = e$$

elne=e

$$\frac{\sum (\bar{x} - x_i)^2}{n-1}$$
8 / 37

I know you love your formulas

$$e^{\ln{e}} = e$$

elne=e

$$\frac{\sum (\bar{x} - x_i)^2}{n-1}$$

(x¯xi)2n1

8 / 37

I know you love your formulas

$$e^{\ln{e}} = e$$

elne=e

$$\frac{\sum (\bar{x} - x_i)^2}{n-1}$$

(x¯xi)2n1

ad nauseam

Enter LATEX code in the same way.

8 / 37

Quickstart with Markdown

9 / 37

Markdown's Philosophy

Keep. it. Simple.

  • No formating/styling. Content only

  • Pleasant to the eye

  • Portable

10 / 37

That's R Markdown (.Rmd)

11 / 37

Simple R Markdown code

```
Admire this curve:
curve(dnorm(x), from = -2, to = 2)
```
12 / 37

Simple R Markdown code

```
Admire this curve:
curve(dnorm(x), from = -2, to = 2)
```

Admire this curve:

12 / 37

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.
13 / 37

What's RMarkdown good for?

14 / 37

Websites/ Blogs

15 / 37

Reports

16 / 37

Books

17 / 37

Slides






👌

18 / 37

Papaja: a template for APA papers

19 / 37

yart: a template for research reports

20 / 37

Why should I use it?

21 / 37

RMarkdown has more power

22 / 37

But I love MS Word...

Start writing with Word. Keep on writing. Sooner or later ...

Markdown does not choke at big documents.

23 / 37

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.
24 / 37

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

24 / 37

Word's typography is so 80ies

Word :

Latex (Markdown):

25 / 37

Do cool stuff

26 / 37

Interactive diagrams

27 / 37

Sample project

28 / 37

Book "Moderne Datenanalyse mit R"

  • 500 pages
  • ~200 figures
  • ~200 R listings

Big thing.

No choking, but long compilation.

29 / 37

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",
...
]
30 / 37

Config file

title: "Moderne Datenanalyse mit R"
subtitle: "Entwurf"
author: "Sebastian Sauer"
lang: de-De
documentclass: book
classoption: a4paper
fontsize: 11pt
fontfamily: mathpazo
...
31 / 37

Sample page

32 / 37

Now what?

33 / 37

Get going with this book

34 / 37

Or with this one

35 / 37

Disclaimer: There may be issues at times

StackOverflow is your friend

36 / 37

Thank you

Sebastian Sauer

sebastiansauer

ssauer@posteo.de

Sebastian Sauer

Get slides here:

http://data-se.netlify.com/slides/rmd-writing/rmd-writing_dgps2018.html#1

CC-BY

Built using R, RMarkdown, Xaringan. Inspiration from and thanks to Yihui Xie and Antoine Bichat, among others

37 / 37

What is RMarkdown?

2 / 37
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow