Skip to content
Open source book: Geocomputation with R
Branch: master
Clone or download
Latest commit 68ddb6e Mar 23, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
code Print congruence image Feb 26, 2019
coffeeApp tiny style fixes Oct 1, 2018
css css update to Yihui's repo Sep 20, 2018
extdata Update readme Mar 10, 2019
figures Update readme Mar 10, 2019
.Rbuildignore update section on mapview May 11, 2018
.gitignore Fix #358 Jan 6, 2019
02-spatial-data.Rmd fixes for dplyr 0.8 Feb 26, 2019
03-attribute-operations.Rmd list-column -> list column Feb 3, 2019
04-spatial-operations.Rmd replace sum function by minimum function in focal figure caption Feb 25, 2019
05-geometry-operations.Rmd fixes issue with rotation Mar 23, 2019
06-reproj.Rmd fixes for dplyr 0.8 Feb 26, 2019
07-read-write-plot.Rmd WKT is well-known text. Fix Feb 2, 2019
13-location.Rmd fixes style Mar 20, 2019
Dockerfile update section on mapview May 11, 2018
README.Rmd Update Mar 20, 2019
_bookdown.yml Publish final chapter Aug 26, 2018
cite-geocompr.bib fix typo Jan 11, 2019
ga.html update section on mapview May 11, 2018
our-impact.csv two new prs Sep 6, 2018
packages.bib readme update Aug 15, 2018
refs.bib Update readme Mar 10, 2019

Geocomputation with R

Build Status


This repository hosts the code underlying Geocomputation with R, a book by Robin Lovelace, Jakub Nowosad, and Jannes Muenchow:

Lovelace, Robin, Jakub Nowosad and Jannes Muenchow (2019). Geocomputation with R. The R Series. CRC Press.

This book has been published by CRC Press in the R Series. The online version of this book is free to read at


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).
  • Changes to the code, e.g. to do things in a more efficient way.
  • Suggestions on content (see the project’s issue tracker).

Please see for the book’s style.

Many thanks to all contributors to the book so far via GitHub (this list will update automatically): katygregg, erstearns, eyesofbambi, tyluRp, marcosci, giocomai, mdsumner, rsbivand, pat-s, gisma, ateucher, annakrystalli, gavinsimpson, Henrik-P, Himanshuteli, yutannihilation, jbixon13, katiejolly, layik, mvl22, nickbearman, ganes1410, richfitz, SymbolixAU, wdearden, yihui, chihinl.

During the project we aim to contribute ‘upstream’ to the packages that make geocomputation with R possible. This impact is recorded in our-impact.csv.

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):


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 for information on that.

Once the dependencies have been installed you should be able to build and view a local version the book with:

bookdown::render_book("index.Rmd") # to build the book
browseURL("_book/index.html") # to view it

Running geocompr code in docker

To ease reproducibility we have set-up a docker image (robinlovelace/geocompr on docker hub) containing all the dependencies needed to reproduce the book. After you have installed docker and set-it up on your computer you should be able to reproduce the entire book with the following steps (resulting in output shown below):

# download repo with Windows Powershell or a Unix terminal
git clone 
# or download manually from here:
cd geocompr # navigate into the repo
# on linux and mac:
docker run -d -p 8788:8787 -v $(pwd):/home/rstudio/data -e USERID=$UID -e PASSWORD=pickASafePassWord --name rstudio robinlovelace/geocompr

# on windows:
docker run -d -p 8787:8787 -v ${pwd}:/home/rstudio/data -e PASSWORD=safepassword robinlovelace/geocompr

If it worked you should be able to open-up RStudio server by opening a browser and navigating to http://localhost:8787/ resulting in an up-to-date version of R and RStudio running in a container.

If you see something like this after following the steps above, congratulations: it worked! See for more info.

From this point to build the book you can open projects in the data directory from the project box in the top-right hand corner, and knit index.Rmd with the little knit button above the the RStudio script panel (Ctl+Shift+B should do the same job).

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:


With these additional dependencies installed, you should be able to run the following scripts, which create content for the book, that we’ve removed from the main book build to reduce package dependencies and the book’s build time:

# source("code/cranlogs.R")
# source("code/sf-revdep.R")
# source("code/08-urban-animation.R")
# source("code/08-map-pkgs.R")

Note: the .Rproj file is configured to build a website not a single page. To reproduce this README use the following command:

rmarkdown::render("README.Rmd", output_format = "github_document", output_file = "")

Book statistics

An indication of the book’s progress over time is illustrated below (to be updated roughly every week as the book progresses).

Book statistics: estimated number of pages per chapter over time.


To cite packages used in this book we use code from Efficient R Programming:

# geocompkg:::generate_citations()

This generates .bib and .csv files containing the packages. The current of packages used can be read-in as follows:

pkg_df = readr::read_csv("extdata/package_list.csv")

Other citations are stored online using Zotero.

If you would like to add to the references, please use Zotero, join the open group add your citation to the open geocompr library.

We use the following citation key format:


This can be set from inside Zotero desktop with the Better Bibtex plugin installed (see by selecting the following menu options (with the shortcut Alt+E followed by N), and as illustrated in the figure below:

Edit > Preferences > Better Bibtex

Zotero settings: these are useful if you want to add references.

We use Zotero because it is a powerful open source reference manager that integrates well with the citr package. As described in the GitHub repo Robinlovelace/rmarkdown-citr-demo.


Name Title version
bookdown Authoring Books and Technical Documents with R Markdown [@R-bookdown] 0.7
cartogram Create Cartograms with R [@R-cartogram] 0.1.0
dismo Species Distribution Modeling [@R-dismo] 1.1.4
geosphere Spherical Trigonometry [@R-geosphere] 1.5.7
ggmap Spatial Visualization with ggplot2 [@R-ggmap] 2.6.1
ggplot2 Create Elegant Data Visualisations Using the Grammar of Graphics [@R-ggplot2]
gstat Spatial and Spatio-Temporal Geostatistical Modelling, Prediction [@R-gstat] 1.1.6
historydata Datasets for Historians [@R-historydata] 0.2.9001
htmlwidgets HTML Widgets for R [@R-htmlwidgets] 1.2
kableExtra Construct Complex Table with ‘kable’ and Pipe Syntax [@R-kableExtra] 0.9.0
kernlab Kernel-Based Machine Learning Lab [@R-kernlab] 0.9.26
knitr A General-Purpose Package for Dynamic Report Generation in R [@R-knitr] 1.20
latticeExtra Extra Graphical Utilities Based on Lattice [@R-latticeExtra] 0.6.28
leaflet Create Interactive Web Maps with the JavaScript ‘Leaflet’ [@R-leaflet] 2.0.1
link2GI Linking Geographic Information Systems, Remote Sensing and Other [@R-link2GI] 0.3.0
lwgeom Bindings to Selected ‘liblwgeom’ Functions for Simple Features [@R-lwgeom] 0.1.4
mapview Interactive Viewing of Spatial Data in R [@R-mapview] 2.4.0
microbenchmark Accurate Timing Functions [@R-microbenchmark] 1.4.4
mlr Machine Learning in R [@R-mlr] 2.12.1
osmdata Import ‘OpenStreetMap’ Data as Simple Features or Spatial [@R-osmdata] 0.0.7
pROC Display and Analyze ROC Curves [@R-pROC] 1.12.1
ranger A Fast Implementation of Random Forests [@R-ranger] 0.10.1
raster Geographic Data Analysis and Modeling [@R-raster] 2.6.7
rcartocolor ‘CARTOColors’ Palettes [@R-rcartocolor] 0.0.22
rgdal Bindings for the ‘Geospatial’ Data Abstraction Library [@R-rgdal] 1.3.3
rgeos Interface to Geometry Engine - Open Source (‘GEOS’) [@R-rgeos] 0.3.28
rgrass7 Interface Between GRASS 7 Geographical Information System and R [@R-rgrass7] 0.1.10
rmapshaper Client for ‘mapshaper’ for ‘Geospatial’ Operations [@R-rmapshaper] 0.4.0
rmarkdown Dynamic Documents for R [@R-rmarkdown] 1.10
rnaturalearth World Map Data from Natural Earth [@R-rnaturalearth] 0.2.0
rnaturalearthdata World Vector Map Data from Natural Earth Used in ‘rnaturalearth’ [@R-rnaturalearthdata] 0.1.0
RPostgreSQL R Interface to the ‘PostgreSQL’ Database System [@R-RPostgreSQL] 0.6.2
RQGIS Integrating R with QGIS [@R-RQGIS] 1.0.3
RSAGA SAGA Geoprocessing and Terrain Analysis [@R-RSAGA] 1.1.0
sf Simple Features for R [@R-sf] 0.6.3
sp Classes and Methods for Spatial Data [@R-sp] 1.3.1
spData Datasets for Spatial Analysis [@R-spData]
spDataLarge Large datasets for spatial analysis [@R-spDataLarge]
stplanr Sustainable Transport Planning [@R-stplanr]
tabularaster Tidy Tools for ‘Raster’ Data [@R-tabularaster] 0.5.0
tidyverse Easily Install and Load the ‘Tidyverse’ [@R-tidyverse] 1.2.1
tmap Thematic Maps [@R-tmap] 2.0.1
tmaptools Thematic Map Tools [@R-tmaptools] 2.0.1
tree Classification and Regression Trees [@R-tree] 1.0.39
vegan Community Ecology Package [@R-vegan] 2.5.2
You can’t perform that action at this time.