Introduction to R for the Geosciences

EGU24 Short Course

Authors
Affiliations

Lorena Abad

University of Salzburg

Jakub Nowosad

Adam Mickiewicz University, Poznań

Ewa Grabska-Szwagrzyk

Jagiellonian University

Edzer Pebesma

University of Münster

Published

April 10, 2024

About

These are the materials for the short course “Introduction to R for the Geosciences” at EGU 2024.

When and where? Wednesday, April 17, 19:00-20:00, Room N1

Abstract

R is a free, open-source programming language popularly used for data science, statistical analysis, and visualization. Spatial data analysis has been strongly supported by the R community, that provides tools for data reading, writing and downloading, and for spatial processing, visualizing and modelling. The R-Spatial package ecosystem relies on common libraries for geospatial analysis such as GDAL, GEOS, and PROJ. In this workshop, we will introduce participants to spatial data analysis in R. For this, there will be demonstrations of key R packages like {sf}, {stars}, {terra} for vector and raster data processing. We will also focus on spatial data visualization using the {tmap} package. We will focus on datasets strongly used by the Geoscience community, including satellite imagery.

Schedule

Time Topic
19:00-19:10 Introduction to R-Spatial
19:10-19:30 Vector data
19:30-19:50 Raster data
19:50-20:00 Q&A

Pre-requisites

R installation

A working installation of R (follow CRAN recommendations for your set-up).

R packages

Please run those commands inside the R console:

# Install the remotes package from CRAN Repo
install.packages(remotes)

# Install workshop and its dependencies
remotes::install_github("loreabad6/egu24-sc-R4geosciences")

You can follow along in your own R script, or clone the repository to run the Quarto documents interactively.

Notes on coding style

  1. R has different coding paradigms, most importantly base R, tidyverse and data.table. In this course we use base R, but give some tips to resources for the tidyverse here and there.

  2. The typical assignment notation in R is <-. However, in these materials you will see = used for assignment. Both are completely fine to use and these materials use = just for preference.

  3. Piping: if you are familiar with the tidyverse, you might have seen the use of the %>% operator to concatenate functions. Since R 4.1.0 R introduced a native pipe operator |> and that is what we use in this workshop. If you are curious about how the native pipe works and differences with the magrittr pipe, see here and here.

Acknowledgements

This course is based on the FOSS4G 2022 workshop “Getting started with R and R-spatial” by Nicolas Roelandt and Jakub Nowosad.

The artwork in these materials is by Allison Horst (@allison_horst).