-
Notifications
You must be signed in to change notification settings - Fork 14
/
functions.Rmd
47 lines (38 loc) · 1.28 KB
/
functions.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
46
47
```{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) Functions {-}
# Introduction
R is well-suited to a functional style of programming, which means you'll often find yourself solving problems by applying various functions. For example, think about how you manipulate a tibble by applying a series of dplyr verbs until you arrive at the result you want.
Because of this, it's important to understand how functions work in R. The following chapters assume you already have experience writing functions in R, and immediately dive into some different types of functions: vector, scalar, predicate, and anonymous.