pkgs <- c(
# --- spatial core (Sessions 2-3) ---
"sf", "terra", "units", "ggspatial",
# --- trajectories and metrics (Sessions 3-4) ---
"amt", "adehabitatLT", "bcpa", "move2",
# --- simulation (Session 5) ---
"circular",
# --- home ranges (Session 6) ---
"adehabitatHR", "ctmm",
# --- selection functions (Session 7) ---
"survival",
# --- hidden Markov models (Session 8) ---
"momentuHMM",
# --- wrangling and graphics ---
"tidyverse", "lubridate", "patchwork",
# --- environmental data (optional) ---
"MODISTools",
# --- documents ---
"knitr", "rmarkdown"
)
missing <- pkgs[!vapply(pkgs, requireNamespace, logical(1), quietly = TRUE)]
if (length(missing)) install.packages(missing) else message("All set.")Software setup
Do this before Session 1
Everything in this course runs on free, open-source software. Budget about 45 minutes for this page — spatial packages are large and compile slowly.
1. R
Install R ≥ 4.3 from cran.r-project.org.
-
Windows — download the
.exe, accept the defaults. -
macOS — download the
.pkgmatching your chip (Apple silicon vs Intel). - Linux — use your distribution’s packages, or r2u on Ubuntu for fast binary installs.
2. RStudio
Install RStudio Desktop from posit.co/download/rstudio-desktop. It bundles Quarto, so you do not need to install Quarto separately.
3. System libraries (Linux only)
sf and terra wrap the GDAL/GEOS/PROJ C++ libraries. macOS and Windows get pre-built binaries; Linux usually needs the development headers first:
sudo apt install libgdal-dev libgeos-dev libproj-dev libudunits2-dev libssl-dev4. R packages
Open RStudio and paste this into the console. It installs only what is missing, so it is safe to rerun.
sf or terra fail to compile (Linux/macOS) — you are missing the system libraries in step 3. Install them, restart R, try again.
Warning: package 'X' is in use and will not be installed — restart R (Session → Restart R) and rerun before loading anything.
Everything is glacially slow — you are compiling from source. On Windows and macOS choose “no” when asked “Do you want to install from sources the package which needs compilation?”.
Corporate or university proxy blocks CRAN — set a mirror explicitly: options(repos = c(CRAN = "https://cloud.r-project.org")).
5. Check your installation
Run this. If it prints a green-ish summary with no MISSING lines, you are ready.
need <- c("sf", "terra", "amt", "adehabitatLT", "adehabitatHR", "ctmm",
"bcpa", "momentuHMM", "circular", "tidyverse", "ggspatial")
for (p in need) {
ok <- requireNamespace(p, quietly = TRUE)
cat(sprintf("%-14s %s\n", p, if (ok) as.character(packageVersion(p)) else "MISSING"))
}
# GDAL / GEOS / PROJ must all report a version:
sf::sf_extSoftVersion()6. Get the course project
The tidiest way to work is to keep everything in one folder.
git clone https://github.com/GiulianoColosimo/animtrack-2627.gitThen open animtrack-2627.Rproj in RStudio. You get every update with git pull.
Go to the repository, click Code → Download ZIP, unzip it somewhere sensible (not inside a syncing folder that renames files), and open the .Rproj file.
Working inside the project means every path in the exercises — data/buffalo_kruger.csv.gz and friends — resolves without you editing anything.
7. A five-minute R refresher
If R is new to you, these are worth the evening:
- R for Data Science (2e), chapters 1–5 — the standard introduction to the data-wrangling verbs used throughout.
-
Spatial Data Science with R and
terra— the reference for Sessions 2 and 3. - Geocomputation with R — the best free GIS-in-R book.
The three things you must be comfortable with before Session 2: