Prerequisites

This is the first practical chapter of the book, and therefore it comes with some software requirements.We assume that you have an up-to-date version of R installed and that you are comfortable using software with a command-line interface such as the integrated development environment (IDE) RStudio.

If you are new to R, we recommend reading Chapter 2 of the online book Efficient R Programming by Gillespie and Lovelace (2016) andlearning the basics of the language with reference to resources such as Grolemund and Wickham (2016) or DataCamp before proceeding.Organize your work (e.g., with RStudio projects) and give scripts sensible names such as chapter-02.R to document the code you write as you learn.

The packages used in this chapter can be installed with the following commands:5

  1. install.packages("sf")
  2. install.packages("raster")
  3. install.packages("spData")
  4. devtools::install_github("Nowosad/spDataLarge")

If you’re running Mac or Linux, the previous command to install sf may not work first time.These operating systems (OSs) have ‘systems requirements’ that are described in the package’s README.Various OS-specific instructions can be found online, such as the article Installation of R 3.5 on Ubuntu 18.04 on the blog rtask.thinkr.fr.

All the packages needed to reproduce the contents of the book can be installed with the following command: devtools::install_github("geocompr/geocompkg").The necessary packages can be ‘loaded’ (technically they are attached) with the library() function as follows:

  1. library(sf) # classes and functions for vector data
  2. library(raster) # classes and functions for raster data

The other packages that were installed contain data that will be used in the book:

  1. library(spData) # load geographic data
  2. library(spDataLarge) # load larger geographic data