forked from itsleeds/rrsrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
177 lines (138 loc) · 7.23 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
title: "Reproducible road safety research with R: A practical introduction"
author: "Robin Lovelace"
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::gitbook: default
# bookdown::word_document2: default
# bookdown::pdf_book: default
description: "A reproducible and open source approach to applied road safety research"
url: 'https\://ITSLeeds.github.io/rrsrr/'
book_filename: rrsrr
github-repo: "ITSLeeds/rrsrr"
bibliography:
- packages.bib
- references.bib
---
```{r, eval=FALSE, echo=FALSE}
# custom outputs
bookdown::render_book("index.Rmd", output_format = "bookdown::word_document2")
file.rename("_book/_main.docx", "rrsrr.docx")
```
```{r knitopts, echo=FALSE}
knitr::opts_chunk$set(fig.path = "figures/")
```
```{r, include=FALSE}
if(file.exists("~/uaf/allrefs.bib")) {
# citr::tidy_bib_file(rmd_file = "_main.Rmd", messy_bibliography = "~/uaf/allrefs.bib", file = "references.bib")
system("find . -name '0*.Rmd' -exec cat {} \\; > /tmp/all.Rmd")
system("echo '@baath_state_2012' >> /tmp/all.Rmd")
citr::tidy_bib_file(rmd_file = "/tmp/all.Rmd", messy_bibliography = "~/uaf/allrefs.bib", file = "references.bib")
}
```
```{r cite, echo=FALSE}
pkgs = c(
"stats19", # downloads and formats open stats19 crash data
"sf", # spatial data package
"tidyverse", # a 'metapackage' with many functions for data processing
"tmap", # for making maps
"pct", # access travel data from DfT-funded PCT project
"stplanr" # transport planning tools
)
knitr::write_bib(x = pkgs, "packages.bib")
rm(pkgs)
```
<!-- Structure outline -->
<!-- Preface -->
<!-- 1 Introduction -->
<!-- 2 R basics -->
<!-- 3 Using RStudio -->
<!-- 4 R Packages -->
<!-- 5 Manipulating data -->
<!-- 6 Temporal data -->
<!-- 7 Spatial data -->
<!-- 8 Joining road crash tables -->
<!-- 9 Next steps for reproducible road safety research -->
<!-- Structure full -->
<!-- Preface -->
<!-- 1 Introduction -->
<!-- 1.1 Why R for road safety research? . . . . . . . . . . . . . . . . . . -->
<!-- 1.2 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -->
<!-- 2 R basics -->
<!-- 2.1 Subsetting by index or name . -->
<!-- 2.2 Subsetting by values . . . . . . -->
<!-- 2.3 Dealing with NAs and recoding -->
<!-- 2.4 Changing class . . . . . . . . . -->
<!-- 2.5 Recoding values . . . . . . . . . -->
<!-- 2.6 Now you are ready to use R . . -->
<!-- 3 Using RStudio -->
<!-- 3.1 Projects and scripts . . . -->
<!-- 3.2 Writing and running code -->
<!-- 3.3 Viewing Objects . . . . . -->
<!-- 3.4 Autocompletion . . . . . . -->
<!-- 3.5 Getting help . . . . . . . . -->
<!-- 3.6 Commenting Code . . . . -->
<!-- 3.7 The global environment . -->
<!-- 3.8 Debugging Code . . . . . -->
<!-- 3.9 Saving R objects . . . . . -->
<!-- 4 R Packages -->
<!-- 4.1 What are packages? . . . . . . . . . . . . . . . . . . . . . . . . . 19 -->
<!-- 4.2 ggplot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 -->
<!-- 4.3 dplyr and pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 -->
<!-- 5 Manipulating data -->
<!-- 6 Temporal data -->
<!-- 7 Spatial data -->
<!-- 7.1 sf objects . . . . . . . . . . . . . . . . -->
<!-- 7.2 Reading and writing spatial data . . . -->
<!-- 7.3 sf polygons . . . . . . . . . . . . . . . -->
<!-- 7.4 Spatial subsetting and sf plotting . . . -->
<!-- 7.5 Geographic joins . . . . . . . . . . . . -->
<!-- 7.6 CRSs . . . . . . . . . . . . . . . . . . . -->
<!-- 7.7 Buffers . . . . . . . . . . . . . . . . . . -->
<!-- 7.8 Attribute operations on sf objects . . . -->
<!-- 7.9 Matching roads to crashes . . . . . . . -->
<!-- 7.10 Mapping road crash data . . . . . . . -->
<!-- 7.11 Analysing point data . . . . . . . . . . -->
<!-- 7.12 Analysing crash data on road networks -->
<!-- 8 Joining road crash tables -->
<!-- 9 Next steps for reproducible road safety research -->
# Preface {-}
Many areas of research have real world implications, but few have the ability to *save lives* in the way that road safety research does.
Road safety research is a data driven field, underpinned by attribute-rich spatio-temporal event-based datasets representing the grim reality of people who are tragically hurt or killed on the roads.
Because of the incessant nature of road casualties, there is a danger that it becomes normalised, an implicitly accepted cost associated with the benefits of personal mobility.
Data analysis in general and 'data science' in particular has great potential to support more evidence-based road safety policies.
Data science can be defined as a particular type of data analysis process, in that it is script-based, reproducible and scalable.
As such, it has the ability to represent what we know about road casualties in new ways, demonstrate the life-saving impacts of effective policies, and prioritise interventions that are most likely to work.
This manual was not designed to be a static textbook that is read once and accumulates dust.
It is meant to be a hand-book, taken out into the field of applied research and referred to frequently in the course of an analysis project.
As such, it is applied and exercise based.
There are strong links between data science, open data, open source software and more collaborative ways of working.
As such, this book is itself a collaborative and open source project that is designed to be a living document.
We encourage any comments, questions or contributions related to its contents, the source code of which can be found at the Reproducible Road Safety Research with R ([rrsrr](https://github.com/ITSLeeds/rrsrr)) repo on the [ITSLeeds GitHub organisation](https://github.com/ITSLeeds/), via the [issue tracker](https://github.com/ITSLeeds/rrsrr/issues).
More broadly, we hope you enjoy the contents of the book and find the process of converting data science into data driven policy changes and investment rewarding.
Get ready for and enjoy the ride!
## Thanks {-}
```{r, include=FALSE}
if("gh" %in% installed.packages()) {
contributors = source("code/list-contributors.R")[[1]]
# save for future reference:
readr::write_csv(contributors, "contributors.csv")
# table view:
# knitr::kable(contributors, caption = "Contributors to Geocomputation with R")
# text view
}
contributors = readr::read_csv("contributors.csv")
c_txt = contributors$name
c_url = contributors$link
c_rmd = paste0("[", c_txt, "](", c_url, ")")
contributors_text = paste0(c_rmd, collapse = ", ")
```
Many thanks to everyone who made this happen, especially RAC Foundation for funding the project, Malcolm Morgan and Andrea Gilardi for contributing to earlier versions, and the Department for Transport for funding reproducible road safety research through the SaferActive project.
Many thanks to all contributors to the book so far via GitHub (this list will update automatically): `r contributors_text`.
This version of the book book was built `r Sys.time()` with the [bookdown](https://bookdown.org/) package and `r R.version$version.string`.
<!-- Comments/questions: should the stats19 package be introduced in a paper of its own right? -->
<!-- If you need PDF output, uncomment bookdown::pdf_book above in YAML. You will need a LaTeX installation, e.g., https://yihui.name/tinytex/ -->
<!-- ## Tests {-} -->
<!-- References that failed initially. -->
<!-- [@baath_state_2012] -->