Run common code at the start of every chapter

This commit is contained in:
hadley 2016-02-17 16:33:25 +11:00
parent 9e2fc73aac
commit 62752f4918
10 changed files with 12 additions and 30 deletions

View File

@ -25,3 +25,5 @@ rmd_files: [
"rmarkdown.Rmd",
"shiny.Rmd",
]
before_chapter_script: "_common.R"

10
_common.R Normal file
View File

@ -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)

View File

@ -1,7 +0,0 @@
set.seed(1014)
options(digits = 3)
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE
)

View File

@ -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
```

View File

@ -1,7 +1,6 @@
# Introduction
```{r setup-intro, include = FALSE}
source("common.R")
install.packages <- function(...) invisible()
```

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -2,9 +2,6 @@
```{r, include = FALSE}
library(ggplot2)
knitr::opts_chunk$set(
cache = TRUE
)
```

View File

@ -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 analysts 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?