forked from geocompx/geocompr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
150 lines (107 loc) · 5.48 KB
/
README.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
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file - rmarkdown::render('README.Rmd', output_format = 'md_document', output_file = 'README.md') -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figures/"
)
is_online = curl::has_internet()
```
# Geocomputation with R
[![Build Status](https://travis-ci.org/Robinlovelace/geocompr.svg?branch=master)](https://travis-ci.org/Robinlovelace/geocompr)
# Introduction
This repository hosts the code underlying Geocomputation with R, a book by [Robin Lovelace](http://robinlovelace.net/), [Jakub Nowosad](https://nowosad.github.io/), and [Jannes Muenchow](http://www.geographie.uni-jena.de/en/Muenchow.html).
The online version of the book is developed at http://robinlovelace.net/geocompr/.
We plan to publish the hard copy of the book with CRC Press in 2018.
## Contributing
We encourage contributions on any part of the book, including:
- Improvements to the text, e.g. clarifying unclear sentences, fixing typos (see guidance from [Yihui Xie](https://yihui.name/en/2013/06/fix-typo-in-documentation/)).
- Changes to the code, e.g. to do things in a more efficient way.
- Suggestions on content (see the project's [issue tracker](https://github.com/Robinlovelace/geocompr/issues) and the [work-in-progress](https://github.com/Robinlovelace/geocompr/tree/master/work-in-progress) folder for chapters in the pipeline).
Please see [our_style.md](https://github.com/Robinlovelace/geocompr/blob/master/our_style.md) for the book's style.
## Reproducing the book
To ease reproducibility, this book is also a package. Installing it from GitHub will ensure all dependencies
to build the book are available on your computer (you need [**devtools**](https://github.com/hadley/devtools)):
```{r, eval=is_online, message=FALSE}
devtools::install_github("robinlovelace/geocompr")
```
You need a recent version of the GDAL, GEOS, Proj.4 and UDUNITS libraries installed for this to work on Mac and Linux. See the **sf** package's [README](https://github.com/edzer/sfr) for information on that.
Once the dependencies have been installed you should be able to build and view a local version the book with:
```{r, eval=FALSE}
bookdown::render_book("index.Rmd") # to build the book
browseURL("_book/index.html") # to view it
```
## Reproducing this README
To reduce the book's dependencies, scripts to be run infrequently to generate input for the book are run on creation of this README.
The additional packages required for this can be installed as follows:
```{r}
pkgs = c("cranlogs", "diagram", "globe", "tidytext")
to_install = !pkgs %in% installed.packages()
if(any(to_install)) {
install.packages(pkgs[to_install])
}
```
With these additional dependencies installed, you should be able to run the following scripts, which create input figures for the book:
```{r cranlogs, message=FALSE, warning=FALSE, fig.show='hide'}
source("code/cranlogs.R")
source("code/sf-revdep.R")
source("code/sfr-class-diagram-gen.R")
```
Note: the `.Rproj` file is configured to build a website not a single page.
To reproduce this [README](https://github.com/Robinlovelace/geocompr/blob/master/README.Rmd) use the following command:
```{r, eval=FALSE}
rmarkdown::render("README.Rmd", output_format = "md_document", output_file = "README.md")
```
## Book statistics
An indication of the book's progress over time is illustrated below (to be updated roughly every week as the book progresses).
```{r, echo=FALSE, message=FALSE, warning=FALSE}
# Should eventually be n_pages
source("R/generate-chapter-code.R") # shouldn't have to run this
book_stats = readr::read_csv("extdata/word-count-time.csv",
col_types=('iiDd'))
# to prevent excessive chapter count
book_stats = dplyr::filter(book_stats, chapter < 10)
if(Sys.Date() > max(book_stats$date) + 5) {
book_stats_new = generate_book_stats()
book_stats = bind_rows(book_stats, book_stats_new)
readr::write_csv(book_stats, "extdata/word-count-time.csv")
}
library(ggplot2)
book_stats$chapter = formatC(book_stats$chapter, width = 2, format = "d", flag = "0")
book_stats$n_pages = book_stats$n_words / 300
```
```{r bookstats, warning=FALSE, echo=FALSE, fig.width=8, fig.height=4}
ggplot(book_stats) +
geom_area(aes(date, n_pages, fill = chapter), position = "stack") +
ylab("Estimated number of pages") +
xlab("Date") +
scale_x_date(date_breaks = "2 month",
limits = c(min(book_stats$date), as.Date("2018-08-01")),
date_labels = "%b %Y") +
ylim(c(0, 200))
```
Book statistics: estimated number of pages per chapter over time.
## Citations
To cite packages used in this book we use code from [Efficient R Programming](https://csgillespie.github.io/efficientR/):
```{r, warning=FALSE}
geocompr:::generate_citations()
```
This generates .bib and .csv files containing the packages.
The current of packages used can be read-in as follows:
```{r, message=FALSE}
pkg_df = readr::read_csv("extdata/package_list.csv")
```
Other citations are stored online using Zotero and downloaded with:
```{r}
geocompr:::dl_citations(f = "refs.bib", user = 418217, collection = "9K6FRP6N")
```
If you would like to add to the references, please use Zotero, join the [open group](https://www.zotero.org/groups/418217/energy-and-transport) add your citation to the open [geocompr library](https://www.zotero.org/groups/418217/energy-and-transport/items/collectionKey/9K6FRP6N).
## References
```{r}
knitr::kable(pkg_df)
```