Prerequisites

This is not intended to be a primer or introduction to programming or R. Instead, this is a cookbook of sorts to help guide users to applying R in the context of our water resources work. External resources for those interested in the basics are provided below (Familiarity with R and RStudio). A few things required before getting started…

Install R

Download and install the newest version of R for your platform at: https://cloud.r-project.org/. For Windows:

  • click on “Download R for Windows”
  • click on “base”
  • click the download link at the top of the page
  • open the downloaded R-4.x.x.exe file and follow the prompts

For macOS:

  • click on “Download R for (Mac) OS X”
  • Under “Latest release:” click on R-4.x.x.pkg

For Linux:

  • click “Download R for Linux” and choose the appropriate distribution

Install RStudio

Install the latest version of Rstudio Desktop for your platform at: https://rstudio.com/products/rstudio/download/#download

Familiarity with R and RStudio

This text assume some basic familiarity with R and RStudio. At minimum you should know how to start a project in RStudio, have a basic understanding of R packages and functions…

If you are completely new to using R I recommend a few resources below:

https://tinystats.github.io/teacups-giraffes-and-statistics/ - Great if you are completely new to programming, also provides some foundational stats training.

https://rstudio.cloud/learn/primers - This provides self-paced, interactive, fundamental R programming exercises.

Adventures in R - Another self-paced set of videos and excercies. This has a good introduction to the RStudio IDE.

Suggested Packages

This text will use the tidyverse set of packages throughout.

install.pacakges("tidyverse")

Sections on spatial analysis will utilize sf and raster.

install.pacakges(c("sf", "raster"))

Contributions and Editing

This text is rendered using bookdown and GitHub Actions (Xie 2016). This means you can submit issues, add code, or copy and render the book on your own system. The project is located on GitHub. If you clone the project into your RStudio session, the book can be rendered as local website using:

bookdown::render_book("index.Rmd")

Navigate to the \_book subdirectory and open index.html to see the book.

Furthermore, a pdf copy of the book can be generated using:

bookdown::render_book("index.Rmd", "bookdown::pdf_book")

Navigate to the \_book subdirectory and open book.pdf.

References

Xie, Yihui. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.