Loading packages in R Studio using Pacman
# Load packages using pacman
if (!require("pacman")) install.packages("pacman") # Checks if pacman is installed and if not, installs pacman.
pacman::p_load(dplyr, ggplot2, sf, tidyr, readr) # Add or remove packages as needed, then loads packages listed using p_load function
Setting working directory using base r
setwd("C:/documents/r-data/data") # Uses set working directory, followed by project folder PC path.
Loading spatial data using the simple features package
# Uses the sf package to load spatial data (e.g. .shp, .gpkg, .gdb)
shape_data <- st_read("data/shape-data.shp") # Load shape data from the data path - if using Quarto, this can be simple path.
Using the dplyr package to select and rename columns
# Selects columns (variables) required using the dplyr::select function, a pipe (%>%) function is used, then renames id column.
shape_data_selected <- shape_data %>%
dplyr::select(id, type.data, geometry) %>%
dplyr::rename('identifier' = 'id')