Setup

0.1 Install software

This workshop will require the following software installed on your machine:

Please download the appropriate stable release for your operating system.

0.2 Launch RStudio

RStudio is an integrated development environment (IDE) for editing text in the code editor, running commands in the R console, viewing defined objects in the workspace and past commands in the history, and viewing plots, files and help. Here’s a layout of the panes in RStudio, each of which can have several tabs for alternate functionality:

Check out the Help > Cheatsheets > RStudio IDE Cheat Sheet.

0.3 Create RStudio project

In RStudio, please create an RStudio project (File > New Project… > New Directory > Empty Project) to organize your code and data for this workshop into a single folder. Feel free to organize this folder wherever makes sense on your laptop. Here’s what I’m using:

0.3.1 Create relative path to data folder

In order to work through a common set of code and access data files in a consistent manner, getting properly situated with paths will save many headaches. Paths can be referenced as an “absolute” path starting with your drive letter (eg “C:” on Windows or “/Users” on Mac). Absolute paths are specific to platform (Windows / Linux / Mac) and not portable for use on other machines or other users wishing to organize content anywhere else. A “relative” path, meaning relative to your current working directory, is portable. Try these commands in the console of RStudio:

# get working directory
getwd()

# list files in working directory
list.files('.')

# list files one directory up
list.files('..')

# create a directory
dir.create('data')

# set working directory
setwd('data')
setwd('..')

So you discovered the absolute path to your current working directory, and list files in the current directory (.) or one directory up (..). Then you created the “data” directory and set the working directory to be inside of it, then back out of it.

The main reason we created the RStudio project file (filename ends in .Rproj) is to have the same working directory every time you return to this project by double-clicking the *.Rproj file in your file explorer. So paths defined in the code of files there can be based on that same working driectory and consistently work, even if you zip them up and send to a colleague who places them on an arbitrary location on their computer.

0.4 Download data

Please download the following zip files into your newly created “data” folder from above.

Then unzip. You should see the following when listing files (and directories) in the data directory.

list.files('data')
## [1] "NEON-DS-Airborne-Remote-Sensing" "NEON-DS-Landsat-NDVI"           
## [3] "NEON-DS-Met-Time-Series"         "NEON-DS-Site-Layout-Files"      
## [5] "NEONDSAirborneRemoteSensing.zip" "NEONDSLandsatNDVI.zip"          
## [7] "NEONDSMetTimeSeries.zip"         "NEONDSSiteLayoutFiles.zip"      
## [9] "states.geojson"

0.5 Install R Packages

Here’s a bit of code to install packages that we’ll use throughout the workshop. Please copy and paste this code into your console.

# concatenate a vector of package names to install
packages = c(
  # general data science
  'tidyverse',
  # dynamic document creation
  'knitr','rmarkdown',
  # handle spatial data
  'rgdal','raster','sp','sf','geojsonio',
  # spatial data
  'maps',
  # spatial analysis
  'rgeos','geosphere',
  # static plotting & mapping
  'RColorBrewer','ggplot2','rasterVis',
  # interactive plotting & mapping
  'plotly','leaflet','mapview','mapedit')

# loop through packages
for (p in packages){
  
  # if package not installed
  if (!require(p, character.only=T)){
    
    # install package
    install.packages(p)
  }
  
  # load package
  library(p, character.only=T)
}

# report on versions of software & packages
sessionInfo()
## R version 3.4.0 (2017-04-21)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: OS X El Capitan 10.11.6
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] mapedit_0.3.2       rasterVis_0.41      latticeExtra_0.6-28
##  [4] lattice_0.20-35     RColorBrewer_1.1-2  rgeos_0.3-25       
##  [7] maps_3.2.0          geojsonio_0.4.2     rgdal_1.2-11       
## [10] rmarkdown_1.6       knitr_1.17          scales_0.5.0       
## [13] htmltools_0.3.6     mapview_2.1.4       leaflet_1.1.0.9000 
## [16] plotly_4.7.1        raster_2.5-8        units_0.4-6        
## [19] geosphere_1.5-5     sp_1.2-5            bindrcpp_0.2       
## [22] sf_0.5-4            dplyr_0.7.3         purrr_0.2.3        
## [25] readr_1.1.1         tidyr_0.7.1         tibble_1.3.4       
## [28] ggplot2_2.2.1.9000  tidyverse_1.1.1    
## 
## loaded via a namespace (and not attached):
##  [1] nlme_3.1-131      satellite_1.0.0   lubridate_1.6.0  
##  [4] webshot_0.4.1     httr_1.3.1        rprojroot_1.2    
##  [7] tools_3.4.0       backports_1.1.0   R6_2.2.2         
## [10] DBI_0.7           lazyeval_0.2.0    colorspace_1.3-2 
## [13] mnormt_1.5-5      curl_2.8.1        compiler_3.4.0   
## [16] rvest_0.3.2       xml2_1.1.1        bookdown_0.5     
## [19] hexbin_1.27.1     psych_1.7.8       stringr_1.2.0    
## [22] digest_0.6.12     foreign_0.8-69    R.utils_2.5.0    
## [25] base64enc_0.1-3   pkgconfig_2.0.1   htmlwidgets_0.9  
## [28] rlang_0.1.2       readxl_1.0.0      rstudioapi_0.7   
## [31] shiny_1.0.5       bindr_0.1         zoo_1.8-0        
## [34] jsonlite_1.5      crosstalk_1.0.0   R.oo_1.21.0      
## [37] magrittr_1.5      Rcpp_0.12.12      munsell_0.4.3    
## [40] R.methodsS3_1.7.1 stringi_1.1.5     yaml_2.1.14      
## [43] plyr_1.8.4        grid_3.4.0        maptools_0.9-2   
## [46] parallel_3.4.0    forcats_0.2.0     udunits2_0.13    
## [49] haven_1.1.0       hms_0.3           gdalUtils_2.0.1.7
## [52] reshape2_1.4.2    codetools_0.2-15  stats4_3.4.0     
## [55] glue_1.1.1        evaluate_0.10.1   V8_1.5           
## [58] data.table_1.10.4 modelr_0.1.1      png_0.1-7        
## [61] httpuv_1.3.5      foreach_1.4.3     cellranger_1.1.0 
## [64] gtable_0.2.0      assertthat_0.2.0  mime_0.5         
## [67] xtable_1.8-2      broom_0.4.2       viridisLite_0.2.0
## [70] iterators_1.0.8

0.6 Create Rmarkdown file

Rmarkdown is a dynamic document format that allows you to knit chunks of R code with formatted text (aka markdown). We recommend that you use this format for keeping a reproducible research document as you work through the lessons To get started, File > New File > Rmarkdown… and go with default HTML document and give any title you like (default “Untitled” or “test” or “First Rmd” is fine).

Check out the Help > Markdown Quick Reference and Help > Cheatsheets > R Markdown Cheat Sheet.

Here’s a 1 minute video on the awesomeness of Rmarkdown: