Installation procedure - training mapping with R
2020-03-20
1 Attention
You will need to access Internet during the training. Make sure you have sufficient rights to connect to a WIFI network and access the Internet outside your workplace (or that you know how to configure your proxy server or vpn if necessary).
2 Installation procedure for spatial libraries
Geographic data is specific data.
To be able to handle them requires the installation of a number of additional libraries and packages. Please ensure that all the libraries listed below are installed and run without errors**
The installation is more or less complicated depending on your operating system. If you are able to install the QGIS software on your computer, you have already taken a big step!
- Windows: Generally, R libraries contain everything you need to run as is.
- Linux: There is no lack of documentation when it comes to Ubuntu. Orders must be adapted for other distributions.
- MacOS: If you install packages binaries, this should be easy. With sources, it’s often a little more complicated, but if you’re an Apple-lover, you’ll be able to find the information.
2.1 R libraries to install
Here is the list of R libraries that you will need to install to be able to follow the training. All libraries are required. Make sure they can be charged ALL before the training.
To install these packages on Windows and Mac, you should choose to install binaries (If R asks it, do NOT install from source).
In case of problems, refer to instructions below.
# If needed
install.packages("remotes")
# Common libraries
remotes::install_cran(c("units", "dplyr", "purrr", "readr", "here", "ggrepel",
"broom", "foreign", "ggforce", "tidyr", "ggplot2", "cowplot", "DBI", "RPostgreSQL", "RPostgres", "rmarkdown", "dbplyr", "rgl"))
# Spatial libraries
remotes::install_cran(c("sp", "rgdal", "raster", "rgeos", "sf", "dichromat", "tmap", "tmaptools", "cartography", "leaflet", "mapview", "mapedit", "ggmap", "rasterVis", "ggspatial", "suncalc", "rayshader", "ggsn", "rpostgis", "rnaturalearth"))
# Github libraries
remotes::install_github("statnmap/cartomisc")
remotes::install_github("smithjd/sqlpetr")
If everything went well, go directly to paragraph ??.
3 Library {sf}
https://github.com/r-spatial/sf
3.1 Installing
This procedure also allows installing {sp}, {rgdal}, {rgeos} and {raster}
Install either from CRAN with:
This will install binary packages on Windows and MacOS, unless you configured R such that it tries to install source packages; in that case, see below.
3.1.1 Windows
Installing {sf} from source works under windows when Rtools is installed. This downloads the system requirements from rwinlib.
3.1.2 MacOS
One way to install the dependencies is using sudo
; the other is using homebrew. For the latter, see e.g. here. Homebrew commands might be:
brew unlink gdal
brew tap osgeo/osgeo4mac && brew tap --repair
brew install proj
brew install geos
brew install udunits
brew install gdal2 --with-armadillo --with-complete --with-libkml --with-unsupported
brew link --force gdal2
after that, you should be able to install {sf} as a source package.
For MacOS Sierra, see these instruction, using kyngchaos frameworks.
In R, in the console. (If you are asked to install using sources, choose “NO”)
3.1.3 Linux
For Unix-alikes, GDAL (>= 2.0.0), GEOS (>= 3.3.0) and Proj(.4) (>= 4.8.0) are required.
3.1.3.1 Ubuntu
To install the dependencies on Ubuntu, either add ubuntugis-unstable to the package repositories:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev libgdal1-dev libgeos-dev
sudo apt-get install libproj-dev libcairo2-dev
or install dependencies from source; see e.g. an older travis config file for hints.
If there is any problem, please refer to our blog post
3.1.3.2 Fedora
The following command installs all required dependencies:
3.1.3.3 Other
To install on Debian, the rocker geospatial Dockerfiles may be helpful. Ubuntu Dockerfiles are found here.
4 Library lwgeom
4.1 Installation
https://github.com/r-spatial/lwgeom
Install from CRAN with:
this will install binary packages on Windows. For MacOS or Linux, you need first to install package “liblwgeom” on your machine.
4.1.1 MacOS
According to https://github.com/r-spatial/sf/issues/349, brew install postgis
installs a working liblwgeom. In case of problems, search for brew in the {sf} issues before opening a new one.
5 Library tmap
5.1 Installation
{tmap} is available on CRAN. Installation is straightforward:
install.packages("tmap")
this will install binary packages on Windows, for other operating systems, see below.
5.1.1 MacOS
One way to install the dependencies is using sudo
; the other is using homebrew. For the latter, see e.g. here. Homebrew commands might be:
brew unlink gdal
brew tap osgeo/osgeo4mac && brew tap --repair
brew install proj
brew install geos
brew install udunits
brew install gdal2 --with-armadillo --with-complete --with-libkml --with-unsupported
brew link --force gdal2
after that, you should be able to install {tmap} as a source package.
If there is any problem, refer to http://www.kyngchaos.com and issue thread
5.1.2 Linux
5.1.2.1 Ubuntu
These Linux packages should be installed prior to the R package.
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libgdal1-dev libgeos-dev libproj-dev libudunits2-dev
sudo apt-get install libv8-dev libjq-dev libprotobuf-dev protobuf-compiler
sudo apt-get install libssl-dev libcairo2-dev
If needed, see installation procedure on github repository for {tmap} : installation script for Ubuntu 16 and Ubuntu 17. See also issue thread
6 Test your installation
You need to verify that your packages installation worked.
Open Rstudio (or your preferred R console) :
There may be some messages but there should not be any problem listed while loading these packages. If this is not the case, verify that you have correctly installed everything listed above.