-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiteration.Rmd
45 lines (37 loc) · 1.11 KB
/
iteration.Rmd
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
```{r include=FALSE, cache=FALSE}
set.seed(2466)
options(
digits = 3,
dplyr.print_max = 6,
dplyr.print_min = 6
)
knitr::opts_chunk$set(
cache = TRUE,
collapse = TRUE,
comment = "#>",
fig.align = 'center',
fig.asp = 0.618, # 1 / phi
fig.show = "hold"
)
image_dpi <- 125
# Stamps plots with a tag
# Idea from Claus Wilke's "Data Visualization" https://serialmentor.com/dataviz/
stamp <- function(
tag = "Bad", tag_color = "#B33A3A", tag_size = 16, tag_padding = 1
)
{
list(
theme(
plot.tag = element_text(color = tag_color, size = tag_size),
plot.tag.position = "topright"
),
labs(
tag =
str_pad(tag, width = str_length(tag) + tag_padding, side = "left")
)
)
}
```
# (PART) Iteration {-}
# Introduction
It's often useful to apply the same function to every element of a vector, list, or tibble. The purrr package contains a set of useful functions for iterating over data structures and performing the same action at each element. In this section, we'll introduce some of the most useful purrr functions and explain how to apply them in different situations.