System installation

Welcome to Get Spatial! Before working through the set of activities it’s best to have a recent version of R and RStudio.

For reference, these activities were written using R version 3.6.1 (2017-01-27) on a Windows machine (x86_64-pc-linux-gnu (64-bit))

Update R and RStudio

You can install or update to the latest version of Rhere and RStudio here



Install required packages

Before starting, run the following code to get all the packages we use in the activities / tutorials.

install.packages(c("devtools","animation","dismo",
                   "gdalUtils","geosphere","ggplot2",
                   "gstat","ks","leaflet","lwgeom",
                   "maptools","mapview","raster",
                   "rasterVis","rgdal","rgeos","sf",
                   "sp","spatstat","tidyverse","velox"), dependencies = TRUE)

if(any(!(pkgs %in% installed.packages()))){
  install.packages(pkgs[!(pkgs %in% installed.packages())],
                   dependencies = TRUE)}

We also need some newer versions of packages that are only available on GitHub. Once you run the above code and/or have the devtools package you can get the required functions by running the following:

devtools::install_github("tidyverse/rlang", build_vignettes = TRUE)
devtools::install_github("tidyverse/ggplot2")

Back to top

On Mac

Download GDAL and install the .dmg file.

Download the rgdal package from CRAN found here.

Place the downloaded rgdal_1.2-16.tgz in your Desktop folder

Run install.packages("~/Desktop/rgdal_1.2-16.tgz", repos=NULL)

Install raster and sp by running: install.packages(c("sp","raster"),dependencies = TRUE)


Back to top

Correct installation

library(raster)
## Loading required package: sp
library(sp)
library(rgeos)
## rgeos version: 0.5-1, (SVN revision 614)
##  GEOS runtime version: 3.5.0-CAPI-1.9.0 
##  Linking to sp version: 1.3-1 
##  Polygon checking: TRUE
library(rgdal)
## rgdal: version: 1.4-4, (SVN revision 833)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.2, released 2017/09/15
##  Path to GDAL shared files: /usr/share/gdal/2.2
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.3-1

Running Windows and interested in MODIS data? You will need OSGeo4W (available for download here) because it comes with a HDF4 driver.

Setup instructions are based on a very helpful post by Nick Eubank

Download R script Last modified: 2019-09-20 18:26:28