forked from jrnold/r4ds-exercise-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
128 lines (107 loc) · 4.79 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
---
knit: "bookdown::render_book"
title: "R for Data Science: Exercise Solutions"
date: >-
`r format(Sys.Date(), "%B %d, %Y")`
author: ["Jeffrey B. Arnold"]
description: >
Solutions to the exercises in
"R for Data Science" by Garrett Grolemund and Hadley Wickham.
site: bookdown::bookdown_site
github-repo: "jrnold/r4ds-exercise-solutions"
url: 'http\://jrnold.github.io/r4ds-exercise-solutions'
twitter-handle: jrnld
documentclass: book
bibliography: ["r4ds.bib"]
link-citations: true
biblio-stye: apalike
cover-image: /img/r4ds-exercise-solutions-cover.png
---
```{r include=FALSE,cache=FALSE,purl=FALSE}
# don't cache anything on this page
knitr::opts_chunk$set(cache = FALSE)
```
# Welcome {-}
<img src="./img/r4ds-exercise-solutions-cover.png" width="250" height="375" alt="Cover image" align="right" style="margin: 0 1em 0 1em"/>
This book contains the **exercise solutions** for the book [*R for Data Science*](https://amzn.to/2aHLAQ1), by Hadley Wickham and Garret Grolemund [@WickhamGrolemund2017].
*R for Data Science* itself is available online at [r4ds.had.co.nz](https://r4ds.had.co.nz/), and physical copy is published by O'Reilly Media and available from [amazon](https://amzn.to/2aHLAQ1).
## Acknowledgments {-}
```{r include=FALSE,purl=FALSE,cache=FALSE}
library("magrittr")
# adapted from usethis:::github_repo_spec
github_repo_spec <- function(path = here::here()) {
stringr::str_c(gh::gh_tree_remote(path), collapse = "/")
}
# copied from usethis:::parse_repo_spec
parse_repo_spec <- function(repo_spec) {
repo_split <- stringr::str_split(repo_spec, "/")[[1]]
if (length(repo_split) != 2) {
stop("`repo_spec` must be of the form 'owner/repo'")
}
list(owner = repo_split[[1]], repo = repo_split[[2]])
}
# copied from usethis:::spec_owner
spec_owner <- function(repo_spec) {
parse_repo_spec(repo_spec)$owner
}
# copied from usethis:::spec_repo
spec_repo <- function(repo_spec) {
parse_repo_spec(repo_spec)$repo
}
# Need to use the github API because this info isn't included in the
# commits for GitHub pulls: Github <noreply@github.com>
# adapted from from usethis:::use_tidy_thanks
github_contribs <- function(repo_spec = github_repo_spec(),
excluded = NULL) {
if (is.null(excluded)) {
excluded <- spec_owner(repo_spec)
}
res <- gh::gh("/repos/:owner/:repo/issues",
owner = spec_owner(repo_spec),
repo = spec_repo(repo_spec), state = "all",
filter = "all", .limit = Inf
)
if (identical(res[[1]], "")) {
message("No matching issues/PRs found.")
return(invisible())
}
contributors <- purrr:::map_chr(res, c("user", "login")) %>%
purrr::discard(~.x %in% excluded) %>%
unique() %>%
sort()
glue::glue("[\\@{contributors}](https://github.com/{contributors})") %>%
glue::glue_collapse(sep = ", ", width = Inf, last = ", and")
}
hypothesis_contribs <- function() {
hypothesis_user_url <- function(x) {
username <- stringr::str_match(x, "acct:(.*)@")[1, 2]
url <- stringr::str_c("https://hypothes.is/users/", username)
stringr::str_c("[\\@", username, "](", url, ")")
}
hypothesis_url <- "https://hypothes.is/api/search"
url_pattern <- "https://jrnold.github.io/r4ds-exercise-solutions/*"
annotations <- httr::GET(hypothesis_url,
query = list(wildcard_uri = url_pattern)) %>%
httr::content()
annotations %>%
purrr::pluck("rows") %>%
purrr::keep(~ !.x$flagged) %>%
purrr::map_chr("user") %>%
unique() %>%
purrr::discard(~ .x == "acct:jrnold@hypothes.is") %>%
purrr::map_chr(hypothesis_user_url) %>%
sort() %>%
glue::glue_collapse(sep = ", ", width = Inf, last = ", and ")
}
```
These solutions have benefited from many contributors.
A special thanks to:
- Garrett Grolemund and Hadley Wickham for writing the truly fantastic *R for Data Science*, without whom these solutions would not exist---literally.
- [\@dongzhuoer](https://github.com/dongzhuoer) and [\@cfgauss](https://hypothes.is/users/cfgauss) for careful readings of the book and noticing numerous issues and proposing fixes.
Thank you to all of those who contributed issues or pull-requests on
[GitHub](https://github.com/jrnold/r4ds-exercise-solutions/graphs/contributors)
(in alphabetical order): `r github_contribs()`
Thank you to all of you who contributed annotations on [hypothes.is](https://hypothes.is/search?q=url%3Ajrnold.github.io%2Fr4ds-exercise-solutions%2F*) (in alphabetical order): `r hypothesis_contribs()`.
For another set of solutions for and notes on *R for Data Science* see [Yet Another 'R for Data Science' Study Guide](https://brshallo.github.io/r4ds_solutions/) by [Bryan Shalloway](https://github.com/brshallo).
## License {-}
This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.