-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_rlang.Rmd
103 lines (81 loc) · 3.31 KB
/
04_rlang.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
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
---
title: "Touring tidyverse"
subtitle: "rlang"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
background-image: url(https://raw.githubusercontent.com/r-lib/rlang/master/man/figures/rlang.png)
background-size: 100px
background-position: 90% 6%
# rlang
The rlang package provides tools to work with core language features of R and the tidyverse:
1. The tidy eval framework, which is a well-founded system for non-standard evaluation built on quasiquotation (`!!`) and quoted arguments (`enquo()`).
1. User-friendly error reporting with backtraces and chained errors (`abort()`, `trace_back()`, `with_abort()`).
1. A consistent API for working with base types. Note that overall this is a work in progress that is still in flux.
---
# Initial commit of rlang/lazyeval
First commit: `2014-08-12 21:15` by Hadley Wickham.
Current iteration of rlang is not the first attempt to introduce quasiquotation.
```{r, eval=FALSE}
library(lazyeval)
f = function(col1, col2, new_col_name) {
mutate_call = lazyeval::interp(~ a + b,
a = as.name(col1),
b = as.name(col2))
mtcars %>% mutate_(.dots = setNames(list(mutate_call),
new_col_name))
}
```
---
# Current state
1. Current version - `r packageVersion("rlang")` (dev version!).
1. https://github.com/r-lib/rlang
1. Developed by __Lionel Henry__, Hadley Wickham.
1. 3200+ commits by 31 contributors.
---
# Why tidyeval
1. Programming over quoting `tidyverse` functions (e.g., `dplyr`, `ggplot2`) <sup>1</sup>.
.footnote[
[1] although it's likely you don't need it for most tasks
]
---
background-image: url(https://raw.githubusercontent.com/r-lib/rlang/master/man/figures/rlang.png)
background-size: 100px
background-position: 90% 6%
# 5 big ideas of tidyeval <sup>1</sup>
1. R code is a tree.
1. You can capture the tree by quoting.
1. Unquoting makes it easy to build trees.
1. Quoting + unquoting to write functions.
1. Quosures capture expression and environment.
.footnote[
[1] https://www.youtube.com/watch?v=nERXS3ssntw
]
---
```{r, echo = FALSE}
countdown::countdown_fullscreen(minutes = 4, update_every = 30,
padding = "20%", margin = "5%",
font_size = "8em", line_height = "1.25")
````
---
```{r, echo = FALSE}
countdown::countdown_fullscreen(minutes = 4, update_every = 30,
padding = "20%", margin = "5%",
font_size = "8em", line_height = "1.25")
````
---
# Resources
1. `tidyeval` book - https://tidyeval.tidyverse.org/ or `tidyeval` post - https://rpubs.com/lionel-/tidyeval-introduction
1. `tidyeval` webinar - https://www.rstudio.com/resources/webinars/tidy-eval/
1. "Tidy evaluation in 5 minutes" by Hadley Wickham - https://www.youtube.com/watch?v=nERXS3ssntw
1. Metaprogramming chapters in "Advanced R" - https://adv-r.hadley.nz/meta.html
1. `tidyeval` cheatsheet - https://www.rstudio.com/resources/cheatsheets/
1. Why you might not need tidyeval - https://resources.rstudio.com/rstudio-conf-2019/working-with-names-and-expressions-in-your-tidy-eval-code and https://resources.rstudio.com/rstudio-conf-2019/lazy-evaluation