Chapter 2 Import libraries and sample dataset
We will begin by loading necessary libraries. The sample dataset for this excercise can be downloaded manually from
GitHub
by accessing https://github.com/Vinit-Sehgal/SampleData
![](SampleData-master/images/git_repo.png)
Alternatively, use the following code to download and extract the sample data from GitHub
repository.
Install all necessary packages (Run once).
###############################################################
#~~~ Load required libraries
lib_names=c("terra", "tidyterra", "cetcolor", "scico", "tmap",
"gifski", "lubridate", #"Rcpp",
"raster","ggplot2","unikn","mapview",
"gridExtra","rgdal","fields",
"RColorBrewer","ncdf4","rasterVis",
"rcartocolor","pacman","purrr","moments","tictoc",
"sf", "sp", "exactextractr","readxl",
"snow","future.apply","parallel")
# Load necessary packages
invisible(suppressMessages
(suppressWarnings
(lapply
(lib_names, require, character.only = T))))
# An easy way to load multiple packages is through pacman::p_load
# pacman::p_load("raster","ggplot2","unikn","mapview",
# "gridExtra","rgdal","fields",
# "RColorBrewer","ncdf4","rasterVis", "moments", "tictoc", "tibble")
# Update packages if they are already installed
# update.package(ask = FALSE)
Note: The legacy R spatial infrastructure packages - maptools
, rgdal
and rgeos
have been archived by CRAN from October 16, 2023; these retired packages will continue to be available as source packages on https://cran.r-project.org/src/contrib/Archive but won’t undergo any further development.
We will now download the workshop repository, which contains all data we will use for this exercise.
###############################################################
#~~~ Import sample data from GitHub repository
download.file(url = "https://github.com/Vinit-Sehgal/SampleData/archive/master.zip",
destfile = "SampleData-master.zip") # Download ".Zip"
# Unzip the downloaded .zip file
unzip(zipfile = "SampleData-master.zip")
# getwd() # Current working directory
list.files("./SampleData-master") # List folder contents
## [1] "CMIP_land"
## [2] "functions"
## [3] "images"
## [4] "Largescale_geospatial_analysis_2022.html"
## [5] "Largescale_geospatial_analysis_2023.html"
## [6] "location_points.xlsx"
## [7] "ne_10m_coastline"
## [8] "raster_files"
## [9] "README.md"
## [10] "sample_pdfs"
## [11] "SMAP_L3_USA.nc"
## [12] "SMAPL4_H5"
## [13] "SMAPL4_rasters"
## [14] "SMOS_nc"
## [15] "USA_states"
## [16] "Workbook_DVGAR21-Part1.html"
## [17] "Workbook_DVGAR21-Part2.html"