forked from Tazinho/Advanced-R-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
142 lines (124 loc) · 17 KB
/
index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
title: "Advanced R Solutions"
author: "Malte Grosser, Henning Bumann, Peter Hurford & Robert Krzyzanowski"
date: "`r Sys.Date()`"
knit: "bookdown::render_book"
site: bookdown::bookdown_site
output:
bookdown::gitbook:
includes:
# in_header: html_header.html # uncomment for javascript-pulldowns
config:
toc:
collapse: section
scroll_highlight: yes
before: null
after: null
edit: https://github.com/Tazinho/Advanced-R-Solutions/edit/master/%s
documentclass: book
bibliography: [packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: Tazinho/Advanced-R-Solutions
before_chapter_script: ["before_chapter_script_1.R"]
description: "Solutions to the exercises in Hadley Wickham's book Advanced R."
cover-image: images/advrs_cover3.png
---
# Prerequisites {-}
```{r global_options, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE)
```
```{r fig.align='center', echo=FALSE, include=identical(knitr:::pandoc_to(), 'html')}
knitr::include_graphics('images/advrs_cover.png', dpi = NA)
```
This book aims to contribute solutions to Hadley Wickham's book [Advanced R](http://adv-r.had.co.nz/).
It is planned to finish until end of 2017. The code can be found on [github](https://github.com/Tazinho/Advanced-R-Solutions.git).
The date of the exercise versions in Hadley's book is January 25th 2017.
```{r eval=FALSE, echo = FALSE}
devtools::install_github("rstudio/bookdown")
date()
```
```{r, echo = FALSE, warning=FALSE}
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(tidyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(forcats))
suppressPackageStartupMessages(library(methods))
df <- tibble::tribble(~`1 Data structures`, ~`2 Subsetting`, ~`3 Functions`, ~`4 OO field guide`, ~`5 Environments`, ~`6 Exceptions and debugging`, ~`7 Functional programming`, ~`8 Functionals`, ~`9 Function operators`, ~`10 Non standard evaluation`, ~`11 Expressions`, ~`12 Domain specific languages`, ~`13 Performance`, ~`14 Profiling`, ~`15 Memory`, ~`16 Rcpp`,
"x", "x", "x", "x", "x", "-", "x", "x", "x", "x", "x", "-", "-", "x", "x", "x",
"x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "-", "x", "x", "x", "x",
"x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "-", "x", "-", "x", "x",
"x", "x", "x", "x", "x", NA, "-", "x", "x", "x", "x", "-", "-", "x", "x", "x",
"x", "x", "x", "x", "x", NA, "x", "x", "x", "x", "x", "-", "x", "x", "-", "x",
"x", "x", "x", "x", "x", NA, "x", "x", "-", "x", "x", "-", "-", "x", "-", "-",
"x", "x", "x", "x", "x", NA, "x", "x", "x", "x", "x", "-", "-", "x", "-", "x",
"x", "x", "x", "x", "x", NA, "x", "x", "x", "x", "x", NA, "-", "-", "-", "x",
"x", "x", "x", "-", "x", NA, "x", "x", "x", "x", "x", NA, "-", "x", "-", "x",
"x", "x", "x", "x", "x", NA, "x", "x", "x", "x", "x", NA, "-", "x", NA, "-",
"x", NA, "x", "x", "x", NA, "x", "x", "-", "x", "x", NA, "-", "-", NA, NA,
"x", NA, "x", NA, "x", NA, "x", "-", "-", "x", "-", NA, NA, "x", NA, NA,
"x", NA, "x", NA, "x", NA, "-", "x", "x", "x", "x", NA, NA, "x", NA, NA,
"x", NA, "x", NA, "x", NA, "-", "x", "-", "x", "x", NA, NA, "x", NA, NA,
"x", NA, "x", NA, "x", NA, NA, "x", "x", "x", "x", NA, NA, "x", NA, NA,
NA, NA, "x", NA, NA, NA, NA, "x", "x", "x", "x", NA, NA, NA, NA, NA,
NA, NA, "x", NA, NA, NA, NA, "x", "x", "x", "-", NA, NA, NA, NA, NA,
NA, NA, "x", NA, NA, NA, NA, "x", "-", "x", "-", NA, NA, NA, NA, NA,
NA, NA, "x", NA, NA, NA, NA, "x", "x", "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, "x", "-", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "-", NA, "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, "x", "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, "-", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "-", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "-", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "x", NA, NA, NA, NA, NA)
df[df == "x"] <- TRUE
df[df == "-"] <- FALSE
#df[df == ""] <- NA
df[] <- lapply(df, as.logical)
df <- df %>% mutate(exercise = 1:n())
df <- gather_(df, "chapter", "solved", setdiff(names(df), "exercise"))
df <- df %>% filter(!is.na(solved))
quote_solutions <- mean(df$solved)
df <- df %>% separate(chapter, "nr", sep = " ", remove = FALSE) %>%
mutate(nr = as.integer(nr),
chapter = factor(chapter),
chapter = fct_reorder(chapter, nr, .desc = TRUE),
solved = as.character(solved),
id = 1:n())
df <- as_data_frame(df)
solved_exercises <-
ggplot(df, aes(x = chapter, fill = solved, group = -id)) +
scale_y_continuous(expand = c(0,0)) +
geom_bar(colour = "white") +
theme(legend.position="none",
axis.text.x = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y = element_text(size=12),
axis.title.y = element_blank(),
axis.ticks.y = element_blank()) +
coord_flip() +
theme(axis.line = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank()) +
ggtitle(paste0("Solved exercises (", round(100 * quote_solutions), "%)"))
solved_exercises
```
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work by Malte Grosser, Henning Bumann, Peter Hurford & Robert Krzyzanowski is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>