diff --git a/_bookdown.yml b/_bookdown.yml index abd006c..9c174f5 100644 --- a/_bookdown.yml +++ b/_bookdown.yml @@ -25,3 +25,5 @@ rmd_files: [ "rmarkdown.Rmd", "shiny.Rmd", ] + +before_chapter_script: "_common.R" diff --git a/_common.R b/_common.R new file mode 100644 index 0000000..9546efd --- /dev/null +++ b/_common.R @@ -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) diff --git a/common.R b/common.R deleted file mode 100644 index c32cfea..0000000 --- a/common.R +++ /dev/null @@ -1,7 +0,0 @@ -set.seed(1014) -options(digits = 3) - -knitr::opts_chunk$set( - comment = "#>", - collapse = TRUE -) diff --git a/functions.Rmd b/functions.Rmd index 929fb58..b334d2f 100644 --- a/functions.Rmd +++ b/functions.Rmd @@ -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 ``` diff --git a/intro.Rmd b/intro.Rmd index cbd3d77..ba87dcf 100644 --- a/intro.Rmd +++ b/intro.Rmd @@ -1,7 +1,6 @@ # Introduction ```{r setup-intro, include = FALSE} -source("common.R") install.packages <- function(...) invisible() ``` diff --git a/lists.Rmd b/lists.Rmd index 04b1e1b..0868fa4 100644 --- a/lists.Rmd +++ b/lists.Rmd @@ -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. diff --git a/relational-data.Rmd b/relational-data.Rmd index 8262ad0..39734e1 100644 --- a/relational-data.Rmd +++ b/relational-data.Rmd @@ -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. diff --git a/transform.Rmd b/transform.Rmd index 47a249a..3232799 100644 --- a/transform.Rmd +++ b/transform.Rmd @@ -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. diff --git a/variation.Rmd b/variation.Rmd index 82f3f01..238f606 100644 --- a/variation.Rmd +++ b/variation.Rmd @@ -2,9 +2,6 @@ ```{r, include = FALSE} library(ggplot2) -knitr::opts_chunk$set( - cache = TRUE -) ``` diff --git a/visualize.Rmd b/visualize.Rmd index 1b2923a..e77030d 100644 --- a/visualize.Rmd +++ b/visualize.Rmd @@ -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?