Skip to content

Commit

Permalink
Run common code at the start of every chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Feb 17, 2016
1 parent 9e2fc73 commit 62752f4
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 30 deletions.
2 changes: 2 additions & 0 deletions _bookdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 25,5 @@ rmd_files: [
"rmarkdown.Rmd",
"shiny.Rmd",
]

before_chapter_script: "_common.R"
10 changes: 10 additions & 0 deletions _common.R
Original file line number Diff line number Diff line change
@@ -0,0 1,10 @@
set.seed(1014)
options(digits = 3)

knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
cache = TRUE
)

options(dplyr.print_min = 6, dplyr.print_max = 6)
7 changes: 0 additions & 7 deletions common.R

This file was deleted.

4 changes: 0 additions & 4 deletions functions.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 1,6 @@
# Expressing yourself in code

```{r, include = FALSE}
source("common.R")
knitr::opts_chunk$set(
cache = TRUE
)
library(dplyr)
diamonds <- ggplot2::diamonds
```
Expand Down
1 change: 0 additions & 1 deletion intro.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 1,6 @@
# Introduction

```{r setup-intro, include = FALSE}
source("common.R")
install.packages <- function(...) invisible()
```

Expand Down
1 change: 0 additions & 1 deletion lists.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@

```{r setup-lists, include=FALSE}
library(purrr)
source("common.R")
```

In this chapter, you'll learn how to handle lists, the data structure R uses for complex, hierarchical objects. You're already familiar with vectors, R's data structure for 1d objects. Lists extend these ideas to model objects that are like trees. You can create a hierarchical structure with a list because unlike vectors, a list can contain other lists.
Expand Down
3 changes: 0 additions & 3 deletions relational-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 4,6 @@
library(dplyr)
library(nycflights13)
library(ggplot2)
source("common.R")
options(dplyr.print_min = 6, dplyr.print_max = 6)
knitr::opts_chunk$set(cache = TRUE)
```

It's rare that a data analysis involves only a single table of data. Typically you have many tables of data, and you must combine them to answer the questions that you're interested in. Collectively, multiple tables of data are called __relational data__ because it is the relations, not just the individual datasets, that are particularly important.
Expand Down
5 changes: 0 additions & 5 deletions transform.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 4,6 @@
library(dplyr)
library(nycflights13)
library(ggplot2)
source("common.R")
options(dplyr.print_min = 6, dplyr.print_max = 6)
knitr::opts_chunk$set(
cache = TRUE
)
```

Visualisation is an important tool for insight generation, but it is rare that you get the data in exactly the right form you need for visualisation. Often you'll need to create some new variables or summaries, or maybe you just want to rename the variables or reorder the observations in order to make the data a little easier to work with. You'll learn how to do all that (and more!) in this chapter which will teach you how to transform your data using the dplyr package.
Expand Down
3 changes: 0 additions & 3 deletions variation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 2,6 @@

```{r, include = FALSE}
library(ggplot2)
knitr::opts_chunk$set(
cache = TRUE
)
```


Expand Down
6 changes: 0 additions & 6 deletions visualize.Rmd
Original file line number Diff line number Diff line change
@@ -1,11 1,5 @@
# Data visualisation

```{r setup-visualise, include = FALSE}
knitr::opts_chunk$set(
cache = TRUE
)
```

> "The simple graph has brought more information to the data analyst’s mind than any other device."---John Tukey
Visualization makes data decipherable. Consider what it is like to study a table of raw data. You can examine a couple of values at a time, but you cannot attend to many values at once. The data overloads your attention span, which makes it hard to spot patterns in the data. See this for yourself; can you spot the striking relationship between $X$ and $Y$ in the table below?
Expand Down

0 comments on commit 62752f4

Please sign in to comment.