forked from stephaniehicks/jhustatcomputing2022
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.qmd
630 lines (412 loc) · 25.8 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
---
title: "05 - Literate Statistical Programming"
author:
- name: Leonardo Collado Torres
url: http://lcolladotor.github.io/
affiliations:
- id: libd
name: Lieber Institute for Brain Development
url: https://libd.org/
- id: jhsph
name: Johns Hopkins Bloomberg School of Public Health Department of Biostatistics
url: https://publichealth.jhu.edu/departments/biostatistics
description: "Introduction to literate statistical programming tools including R Markdown"
image: https://github.com/allisonhorst/stats-illustrations/raw/main/rstats-artwork/rmarkdown_rockstar.png
categories: [module 1, week 1, R Markdown, programming]
bibliography: my-refs.bib
---
*This lecture, as the rest of the course, is adapted from the version [Stephanie C. Hicks](https://www.stephaniehicks.com/) designed and maintained in 2021 and 2022. Check the recent changes to this file through the `r paste0("[GitHub history](https://github.com/lcolladotor/jhustatcomputing2023/commits/main/", basename(dirname(getwd())), "/", basename(getwd()), "/index.qmd)")`.*
<!-- Add interesting quote -->
# Pre-lecture materials
### Read ahead
::: callout-note
### Read ahead
**Before class, you can prepare by reading the following materials:**
1. <https://rafalab.github.io/dsbook/reproducible-projects-with-rstudio-and-r-markdown.html>
2. <https://statsandr.com/blog/tips-and-tricks-in-rstudio-and-r-markdown>
:::
### Acknowledgements
Material for this lecture was borrowed and adopted from
- <https://rdpeng.github.io/Biostat776/lecture-literate-statistical-programming.html>
- <https://statsandr.com/blog/tips-and-tricks-in-rstudio-and-r-markdown>
# Learning objectives
::: callout-note
# Learning objectives
**At the end of this lesson you will:**
- Be able to define literate programming
- Recognize differences between available tools to for literate programming
- Know how to efficiently work within RStudio for efficient literate programming
- Create a R Markdown document
:::
# Introduction
One basic idea to make writing reproducible reports easier is what's known as *literate statistical programming* (or sometimes called [literate statistical practice](http://www.r-project.org/conferences/DSC-2001/Proceedings/Rossini.pdf)). This comes from the idea of [literate programming](https://en.wikipedia.org/wiki/Literate_programming) in the area of writing computer programs.
The idea is to **think of a report or a publication as a stream of text and code**.
- The text is readable by people and the code is readable by computers.
- The analysis is described in a series of text and code chunks.
- Each kind of code chunk will do something like load some data or compute some results.
- Each text chunk will relay something in a human readable language.
There might also be **presentation code** that formats tables and figures and there's article text that explains what's going on around all this code. This stream of text and code is a literate statistical program or a literate statistical analysis.
### Weaving and Tangling
Literate programs by themselves are a bit difficult to work with, but they can be processed in two important ways.
Literate programs can be **weaved** to produce human readable documents like PDFs or HTML web pages, and they can **tangled** to produce machine-readable "documents", or in other words, machine readable code.
The basic idea behind literate programming in order to generate the different kinds of output you might need, **you only need a single source document**---you can weave and tangle to get the rest.
In order to use a system like this you need a documentational language, that's human readable, and you need a programming language that's machine readable (or can be compiled/interpreted into something that's machine readable).
### Sweave
One of the original literate programming systems in R that was designed to do this was called Sweave. Sweave enables users to combine R code with a documentation program called $LaTeX$.
**Sweave files ends a `.Rnw`** and have R code weaved through the document:
```
<<plot1, height=4, width=5, eval=FALSE>>=
data(airquality)
plot(airquality$Ozone ~ airquality$Wind)
@
```
Once you have created your `.Rnw` file, Sweave will process the file, executing the R chunks and replacing them with output as appropriate before creating the PDF document.
It was originally developed by Fritz Leisch, who is a core member of R, and the code base is still maintained by R Core. The Sweave system comes with any installation of R.
There are many limitations to the original Sweave system.
- One of the limitations is that it is **focused primarily on** $LaTeX$, which is not a documentation language that many people are familiar with.
- Therefore, it **can be difficult to learn this type of markup language** if you're not already in a field that uses it regularly.
- Sweave also **lacks a lot of features that people find useful** like caching, and multiple plots per page and mixing programming languages.
Instead, folks have **moved towards using something called knitr**, which offers everything Sweave does, plus it extends it further.
- With Sweave, additional tools are required for advanced operations, whereas knitr supports more internally. We'll discuss knitr below.
### rmarkdown
Another choice for literate programming is to build documents based on [Markdown](https://en.wikipedia.org/wiki/Markdown) language. A markdown file is a plain text file that is typically given the extension `.md.`. The [`rmarkdown`](https://CRAN.R-project.org/package=rmarkdown) R package takes a R Markdown file (`.Rmd`) and weaves together R code chunks like this:
````
```{r plot1, height=4, width=5, eval=FALSE, echo=TRUE}`r ''`
data(airquality)
plot(airquality$Ozone ~ airquality$Wind)
```
````
::: callout-tip
The best resource for learning about R Markdown this by Yihui Xie, J. J. Allaire, and Garrett Grolemund:
- <https://bookdown.org/yihui/rmarkdown>
The R Markdown Cookbook by Yihui Xie, Christophe Dervieux, and Emily Riederer is really good too:
- <https://bookdown.org/yihui/rmarkdown-cookbook>
The authors of the 2nd book describe the motivation for the 2nd book as:
> "However, we have received comments from our readers and publisher that it would be beneficial to provide more practical and relatively short examples to show the interesting and useful usage of R Markdown, because it can be daunting to find out how to achieve a certain task from the aforementioned reference book (put another way, that book is too dry to read). As a result, this cookbook was born."
:::
Because this is lecture is built in a `.qmd` file (which is very similar to a `.Rmd` file), let's demonstrate how this work. I am going to change `eval=FALSE` to `eval=TRUE`.
```{r plot2, height=4, width=5, eval=TRUE, echo=TRUE}
data(airquality)
plot(airquality$Ozone ~ airquality$Wind)
```
::: callout-tip
### Questions
1. Why do we not see the back ticks \`\`\` anymore in the code chunk above that made the plot?
2. What do you think we should do if we want to have the code executed, but we want to hide the code that made it?
:::
Before we leave this section, I find that there is quite a bit of terminology to understand the magic behind `rmarkdown` that can be confusing, so let's break it down:
- [Pandoc](https://pandoc.org). Pandoc is a command line tool with no GUI that converts documents (e.g. from number of different markup formats to many other formats, such as .doc, .pdf etc). It is completely independent from R (but does come bundled with RStudio).
- [Markdown](https://en.wikipedia.org/wiki/Markdown) (**markup language**). Markdown is a lightweight [markup language](https://en.wikipedia.org/wiki/Markup_language) with plain text formatting syntax designed so that it can be converted to HTML and many other formats. A markdown file is a plain text file that is typically given the extension `.md.` It is completely independent from R.
- [`markdown`](https://CRAN.R-project.org/package=markdown) (**R package**). `markdown` is an R package which converts `.md` files into HTML. It is no longer recommended for use has been surpassed by [`rmarkdown`](https://CRAN.R-project.org/package=rmarkdown) (discussed below).
- R Markdown (**markup language**). R Markdown is an extension of the markdown syntax. R Markdown files are plain text files that typically have the file extension `.Rmd`.
- [`rmarkdown`](https://CRAN.R-project.org/package=rmarkdown) (**R package**). The R package `rmarkdown` is a library that uses pandoc to process and convert `.Rmd` files into a number of different formats. This core function is `rmarkdown::render()`. **Note**: this package only deals with the markdown language. If the input file is e.g. `.Rhtml` or `.Rnw`, then you need to use `knitr` prior to calling pandoc (see below).
- [quarto](https://quarto.org/): Similar to `rmarkdown` but can be used outside R. It is not an R package! Input files have the `.qmd` file extension.
::: callout-tip
Check out the R Markdown Quick Tour for more:
- <https://rmarkdown.rstudio.com/authoring_quick_tour.html>
:::
![Artwork by Allison Horst on RMarkdown](https://github.com/allisonhorst/stats-illustrations/raw/main/rstats-artwork/rmarkdown_rockstar.png){width="80%"}
### knitr
One of the alternative that has come up in recent times is something called `knitr`.
- The `knitr` package for R takes a lot of these ideas of literate programming and updates and improves upon them.
- `knitr` still uses R as its programming language, but it allows you to mix other programming languages in.
- You can also use a variety of documentation languages now, such as LaTeX, markdown and HTML.
- `knitr` was developed by Yihui Xie while he was a graduate student at Iowa State and it has become a very popular package for writing literate statistical programs.
Knitr takes a plain text document with embedded code, executes the code and 'knits' the results back into the document.
For for example, it converts
- An R Markdown (`.Rmd)` file into a standard markdown file (`.md`)
- An `.Rnw` (Sweave) file into to `.tex` format.
- An `.Rhtml` file into to `.html`.
The core function is `knitr::knit()` and by default this will look at the input document and try and guess what type it is e.g. `Rnw`, `Rmd` etc.
This core function performs three roles:
- A **source parser**, which looks at the input document and detects which parts are code that the user wants to be evaluated.
- A **code evaluator**, which evaluates this code
- An **output renderer**, which writes the results of evaluation back to the document in a format which is interpretable by the raw output type. For instance, if the input file is an `.Rmd`, the output render marks up the output of code evaluation in `.md` format.
```{r rmarkdown-wizards, echo = FALSE, fig.cap = "Converting a Rmd file to many outputs using knitr and pandoc", out.width = '60%', fig.align='center', preview=TRUE}
knitr::include_graphics("https://d33wubrfki0l68.cloudfront.net/61d189fd9cdf955058415d3e1b28dd60e1bd7c9b/9791d/images/rmarkdownflow.png")
```
\[[Source](https://rmarkdown.rstudio.com/authoring_quick_tour.html)\]
As seen in the figure above, from there pandoc is used to convert e.g. a `.md` file into many other types of file formats into a `.html`, etc.
So in summary:
> "R Markdown stands on the shoulders of knitr and Pandoc. The former executes the computer code embedded in Markdown, and converts R Markdown to Markdown. The latter renders Markdown to the output format you want (such as PDF, HTML, Word, and so on)."
\[[Source](https://bookdown.org/yihui/rmarkdown/)\]
# Create and Knit Your First R Markdown Document
<iframe width="560" height="315" src="https://www.youtube.com/embed/dY9KNat_vYs" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
When creating your first R Markdown document, in RStudio you can
1. Go to File \> New File \> R Markdown...
2. Feel free to edit the Title
3. Make sure to select "Default Output Format" to be HTML
4. Click "OK". RStudio creates the R Markdown document and places some boilerplate text in there just so you can see how things are setup.
5. Click the "Knit" button (or go to File \> Knit Document) to make sure you can create the HTML output
If you successfully knit your first R Markdown document, then congratulations!
```{r}
#| label: missionaccomplished
#| echo: false
#| out-width: '60%'
#| fig-cap: "Mission accomplished!"
knitr::include_graphics("https://media.giphy.com/media/L4ZZNbDpOCfiX8uYSd/giphy.gif")
```
# Websites and Books in R Markdown
Now that you are on the road to using R Markdown documents, it is important to know about other wonderful things you do with these documents. For example, let's say you have multiple `.Rmd` documents that you want to put together into a website, blog, book, etc.
There are primarily two ways to build multiple `.Rmd` documents together:
1. [**blogdown**](https://bookdown.org/yihui/blogdown/) for building websites
2. [**bookdown**](https://bookdown.org/yihui/bookdown/) for authoring books
In this section, we briefly introduce both packages, but it's worth mentioning that the [**rmarkdown** package also has a built-in site generator](https://bookdown.org/yihui/rmarkdown/rmarkdown-site.html) to build websites.
### blogdown
```{r}
#| label: hex-blogdown
#| echo: false
#| out-width: '30%'
#| fig-cap: "blogdown logo"
knitr::include_graphics("https://bookdown.org/yihui/blogdown/images/logo.png")
```
\[[Source](https://bookdown.org/yihui/bookdown/images/logo.png)\]
The `blogdown` R package is built on top of R Markdown, supports multi-page HTML output to write a blog post or a general page in an Rmd document, or a plain Markdown document.
- These source documents (e.g. `.Rmd` or `.md`) are built into a static website (i.e. a bunch of static HTML files, images and CSS files).
- Using this folder of files, it is very easy to publish it to any web server as a website.
- Also, it is easy to maintain because it is only a single folder.
::: callout-tip
For example, my personal website was built in blogdown:
- <http://lcolladotor.github.io/>
Other really great examples can be found here:
- <https://awesome-blogdown.com>
:::
Other advantages include the content likely being reproducible, easier to maintain, and easy to convert pages to e.g. PDF or other formats in the future if you do not want to convert to HTML files.
Because it is based on the Markdown syntax, it is easy to write technical documents, including math equations, insert figures or tables with captions, cross-reference with figure or table numbers, add citations, and present theorems or proofs.
Here's a video you can watch of someone making a blogdown website.
<p align="center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/AADnslLpzJ4" frameborder="0" allowfullscreen>
</iframe>
</p>
\[[Source](https://www.youtube.com/watch?v=AADnslLpzJ4) on YouTube\]
### bookdown
```{r}
#| label: hex-bookdown
#| echo: false
#| out-width: '30%'
#| fig-cap: "book logo"
knitr::include_graphics("https://bookdown.org/yihui/bookdown/images/logo.png")
```
\[[Source](https://bookdown.org/yihui/bookdown/images/logo.png)\]
Similar to `blogdown`, the `bookdown` R package is built on top of R Markdown, but also offers features like multi-page HTML output, numbering and cross-referencing figures/tables/sections/equations, inserting parts/appendices, and imported the GitBook style (<https://www.gitbook.com>) to create elegant and appealing HTML book pages. Share
::: callout-tip
For example, the previous version of this course was built in bookdown:
- <https://rdpeng.github.io/Biostat776>
My team documentation website is also built with `bookdown`:
- <https://lcolladotor.github.io/bioc_team_ds/>
Another example is the [Tidyverse Skills for Data Science](https://jhudatascience.org/tidyversecourse/) book that the JHU Data Science Lab wrote. The github repo that contains all the `.Rmd` files can be found [here](https://github.com/jhudsl/tidyversecourse).
- <https://jhudatascience.org/tidyversecourse>
- <https://github.com/jhudsl/tidyversecourse>
:::
**Note**: Even though the word "book" is in "bookdown", this package is not only for books. It really can be anything that consists of multiple `.Rmd` documents meant to be read in a linear sequence such as course dissertation/thesis, handouts, study notes, a software manual, a thesis, or even a diary.
- <https://bookdown.org/yihui/rmarkdown/basics-examples.html#examples-books>
### distill
There is another great way to build blogs or websites using the [distill for R Markdown](https://rstudio.github.io/distill/).
- <https://rstudio.github.io/distill>
Distill for R Markdown combines the technical authoring features of the [Distill web framework](https://github.com/distillpub/template) (optimized for scientific and technical communication) with [R Markdown](https://rmarkdown.rstudio.com), enabling a fully reproducible workflow based on literate programming [@knuth1984].
Distill articles include:
- Reader-friendly typography that adapts well to mobile devices.
- Features essential to technical writing like $LaTeX$ math, citations, and footnotes.
- Flexible figure layout options (e.g. displaying figures at a larger width than the article text).
- Attractively rendered tables with optional support for pagination.
- Support for a wide variety of diagramming tools for illustrating concepts. The ability to incorporate JavaScript and D3-based interactive visualizations.
- A variety of ways to publish articles, including support for publishing sets of articles as a Distill website or as a Distill blog.
The course website from 2021 was built in Distill for R Markdown:
- Website: <https://stephaniehicks.com/jhustatcomputing2021>
- Github: <https://github.com/stephaniehicks/jhustatcomputing2021>
Some other cool things about distill is the use of footnotes and asides.
For example [^1]. The number of the footnote will be automatically generated.
[^1]: This will become a hover-able footnote
You can also optionally include notes in the gutter of the article (immediately to the right of the article text). To do this use the aside tag.
<aside>This content will appear in the gutter of the article.</aside>
You can also include figures in the gutter. Just enclose the code chunk which generates the figure in an aside tag
# Tips and tricks in R Markdown in RStudio
Here are shortcuts and tips on efficiently using RStudio to improve how you write code.
### Run code
If you want to run a code chunk:
```
command + Enter on Mac
Ctrl + Enter on Windows
```
### Insert a comment in R and R Markdown
To insert a comment:
```
command + Shift + C on Mac
Ctrl + Shift + C on Windows
```
This shortcut can be used both for:
- R code when you want to comment your code. It will add a `#` at the beginning of the line
- for text in R Markdown. It will add `<!--` and `-->` around the text
Note that if you want to comment more than one line, select all the lines you want to comment then use the shortcut. If you want to uncomment a comment, apply the same shortcut.
### Knit a R Markdown document
You can knit R Markdown documents by using this shortcut:
```
command + Shift + K on Mac
Ctrl + Shift + K on Windows
```
### Code snippets
Code snippets is usually a few characters long and is used as a shortcut to insert a common piece of code. You simply type a few characters then press `Tab` and it will complete your code with a larger code. `Tab` is then used again to navigate through the code where customization is required. For instance, if you type `fun` then press `Tab`, it will auto-complete the code with the required code to create a function:
```
name <- function(variables) {
}
```
Pressing `Tab` again will jump through the placeholders for you to edit it. So you can first edit the name of the function, then the variables and finally the code inside the function (try by yourself!).
There are many code snippets by default in RStudio. Here are the code snippets you might want to use:
- `lib` to call `library()`
```{r, eval = FALSE}
library(package)
```
- `mat` to create a matrix
```{r, eval = FALSE}
matrix(data, nrow = rows, ncol = cols)
```
- `if`, `el`, and `ei` to create conditional expressions such as `if() {}`, `else {}` and `else if () {}`
```{r, eval = FALSE}
if (condition) {
## Case 1
} else if (condition) {
## Case 2
} else if (condition) {
## Case 3
}
```
- `fun` to create a function
```{r, eval = FALSE}
name <- function(variables) {
}
```
- `for` to create for loops
```{r, eval = FALSE}
for (variable in vector) {
}
```
- `ts` to insert a comment with the current date and time (useful if you have very long code and share it with others so they see when it has been edited)
```{r, eval = FALSE}
# Tue Jan 21 20:20:14 2020 ------------------------------
```
You can see all default code snippets and add yours by clicking on Tools \> Global Options... \> Code (left sidebar) \> Edit Snippets...
### Ordered list in R Markdown
In R Markdown, when creating an ordered list such as this one:
1. Item 1
2. Item 2
3. Item 3
Instead of bothering with the numbers and typing
```
1. Item 1
2. Item 2
3. Item 3
```
you can simply type
```
1. Item 1
1. Item 2
1. Item 3
```
for the exact same result (try it yourself or check the code of this article!). This way you do not need to bother which number is next when creating a new item.
To go even further, any numeric will actually render the same result as long as the first item is the number you want to start from. For example, you could type:
```
1. Item 1
7. Item 2
3. Item 3
```
which renders
1. Item 1
2. Item 2
3. Item 3
However, I suggest always using the number you want to start from for all items because if you move one item at the top, the list will start with this new number. For instance, if we move `7. Item 2` from the previous list at the top, the list becomes:
```
7. Item 2
1. Item 1
3. Item 3
```
which incorrectly renders
7. Item 2
8. Item 1
9. Item 3
### New code chunk in R Markdown
When editing R Markdown documents, you will need to insert a new R code chunk many times. The following shortcuts will make your life easier:
```
command + option + I on Mac (or command + alt + I depending on your keyboard)
Ctrl + ALT + I on Windows
```
### Reformat code
A clear and readable code is always easier and faster to read (and look more professional when sharing it to collaborators). To automatically apply the most common coding guidelines such as white spaces, indents, etc., use:
```
cmd + Shift + A on Mac
Ctrl + Shift + A on Windows
```
So for example the following code which does not respect the guidelines (and which is not easy to read):
```
1+1
for(i in 1:10){if(!i%%2){next}
print(i)
}
```
becomes much more neat and readable:
```
1 + 1
for (i in 1:10) {
if (!i %% 2) {
next
}
print(i)
}
```
I also like to use the [`styler`: Non-invasive pretty printing of R code](https://github.com/r-lib/styler) package to automatically style my R code. I also use <https://lcolladotor.github.io/biocthis/reference/bioc_style.html> to style my code in a way that it is compatible with Bioconductor's code standards.
```{r}
#| eval: false
## Install styler for automatically styling scripts
install.packages("styler")
## Install biocthis
if (!require("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("biocthis")
```
```{r}
## Example code for styling all files that end with .qmd
cat(readLines(here::here("scripts", "auto_style.R")))
```
You might want to edit your `` ~/.Rprofile with `usethis::edit_r_profile()` `` and add this line to it:
```{r}
#| eval: false
## For the styler addin
# Affects the output of: styler:::get_addins_style_transformer_name()
# https://github.com/r-lib/styler/blob/acfb42acc2e558e7b57ef133f1470df78b5093fd/R/addins.R#L183
options("styler.addins_style_transformer" = "biocthis::bioc_style()")
```
For more information I have on my `~/.Rprofile` file check <https://lcolladotor.github.io/bioc_team_ds/config-files.html#rprofile>.
### RStudio addins
RStudio addins are extensions which provide a simple mechanism for executing advanced R functions from within RStudio. In simpler words, when executing an addin (by clicking a button in the Addins menu), the corresponding code is executed without you having to write the code. RStudio addins have the advantage that they allow you to execute complex and advanced code much more easily than if you would have to write it yourself.
::: callout-tip
**For more information about RStudio addins, check out**:
- <https://rstudio.github.io/rstudioaddins>
- <https://statsandr.com/blog/tips-and-tricks-in-rstudio-and-r-markdown>
:::
### Others
Similar to many other programs, you can also use:
- `command + Shift + N` on Mac and `Ctrl + Shift + N` on Windows to open a new R Script
- `command + S` on Mac and `Ctrl + S` on Windows to save your current script or R Markdown document
Check out Tools --\> Keyboard Shortcuts Help to see a long list of these shortcuts.
# Post-lecture materials
### Final Questions
Here are some post-lecture questions to help you think about the material discussed.
::: questions
### Questions
1. What is literate programming?
2. What was the first literate statistical programming tool to weave together a statistical language (R) with a markup language (LaTeX)?
3. What is `knitr` and how is different than other literate statistical programming tools?
4. Where can you find a list of other commands that help make your code writing more efficient in RStudio?
:::
### Additional Resources
::: callout-tip
- [RMarkdown Tips and Tricks](https://indrajeetpatil.github.io/RmarkdownTips/) by Indrajeet Patil
- <https://bookdown.org/yihui/rmarkdown>
- <https://bookdown.org/yihui/rmarkdown-cookbook>
:::
# R session information
```{r}
options(width = 120)
sessioninfo::session_info()
```