Preparation: Getting ready


We normally start our R code by loading the required libraries. Here is an example of how to load R libraries. Boxes with grey background contain code snippets.


#***********************************************************************************
# Set Up: Getting ready
#***********************************************************************************

#===================================================================================
# Load  Libraries
#===================================================================================

library(sp)  # Classes and methods for spatial data (the classes document where the spatial location information resides, for 2D or 3D data).
library(rgdal) # Bindings to Geospatial Data Abstraction Library ('GDAL') and access to projection/transformation operations from 'PROJ.4' library. 


If you haven't installed these libraries yet, you would need to first set a CRAN mirror and then install the libraries using the 'install.packages' function. This can be done via R GUI menus or using R code. The 'README.md' files in TERN's DSDP GitHub pages contain information on how install the R libraries required for all tutorials and workshops. The contents of the README.md files are automatically displayed when you navigate to the tutorials and workshops directories (i.e. one directory and README.md file for each tutorial/workshop).



It is also advisable to change your working directory, to a particularly forder you want to use for your the project you are working on. Before running your R scropt for the first time, you might also what to clean the folder by removing unwanted objects. These step can be conducted as shown in the code below. However, the commands are commented out in case that you don't want to conduct all these steps or want to change some details (e.g. change you directory path and name from that provided). 


#==================================================================================
# Optional Steps (remove comments to run them)
#==================================================================================

# Setting up my Current Working Directory
# ---------------------------------------
#getwd()
#my.CWDir = "C:/Users/uqbblanc/Documents/TERN/CWDir"  # Replace with your Working Directory
#setwd(my.CWDir)
#getwd()

# Clean up Memory
# ---------------
#rm(list=ls())
#list.files()