This repository has been archived by the owner on Aug 20, 2022. It is now read-only.
forked from hadley/adv-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Meta.Rmd
33 lines (22 loc) · 1.59 KB
/
Meta.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
# (PART) Metaprogramming {-}
# Introduction {#meta}
```{r setup, include = FALSE}
source("common.R")
```
> "Flexibility in syntax, if it does not lead to ambiguity, would seem a
> reasonable thing to ask of an interactive programming language."
>
> --- Kent Pitman
R has powerful tools for computing not only on values, but also on the actions that lead to those values. If you're coming from another programming language, they are one of the most surprising features of R. Consider the following simple snippet of code that plots a sine curve:
```{r plot-labels, small_mar = TRUE, fig.width = 3.5, fig.height = 2.5}
x <- seq(0, 2 * pi, length = 100)
sinx <- sin(x)
plot(x, sinx, type = "l")
```
Look at the labels on the axes. How did R know that the variable on the x axis is called `x` and the variable on the y axis is called `sinx`? In most programming languages, you can only access the values of a function's arguments. In R, you can also access the code used to compute them. This makes it possible to evaluate code in non-standard ways: to use what is known as __non-standard evaluation__, or NSE for short. NSE is particularly useful for functions when doing interactive data analysis because it can dramatically reduce the amount of typing. \index{non-standard evaluation}
* Structure of code - symbols, calls, and pairlists.
* Tidy eval, a which forms a principled philosophy for NSE.
* Then talk about the wider variety of NSE found in base R.
* Code generation
* Case studies creating two DSLs in R. One for generating latex, and one
for generation HTML. Combine many of the ideas in this section.