R is an open-source programming language originally developed for statistical analysis. It has gained popularity and functionality throughout the decades and is now a common workhorse for environmental data scientists. Download R from the Comprehensive R Archive Network (CRAN) repository{target="_blank"}. Note that this website has an astounding amount of resources for curious R users (instructions, FAQ's, manuals, and more).
knitr::include_graphics("images\\rproj.PNG")
Click on the link for your computer's operating system (PC, Mac, or Linux), and you will be taken to a page with a few download options (titled "Subdirectories"). For the purposes of this package, click the link next to the "base" version that says "install R for the first time."
knitr::include_graphics("images\\instRfirst.PNG")
The next page provides the download link, which downloads the executable file to your computer. Double clicking the install file opens an installer window. Be sure to note the folder in which you installed the R program.
knitr::include_graphics("images\\wheretoinst.PNG")
When using the install wizard, comply with all default settings. It is highly recommended to create a Desktop or toolbar shortcut during install. Click "Finish" to finish installing R on your computer.
RStudio is a user-friendly program for running R and its many packages. While not required for the secondary review process, RStudio is highly recommended for beginneRs wanting to learn more about R's functionality and syntax. RStudio runs R behind the scenes and gives programmers an organized, clean interface in which to develop and run code.
Head to the RStudio Download Hub{target="_blank"} and select the free RStudio Desktop version for your operating system. Follow the download prompts and stick to default settings.
knitr::include_graphics("images\\rstudioinst.PNG")
Now that you've installed the R program, the next step is to install the necessary R packages.
R code is used to run programs that perform helpful tasks on the computer, from performing statistical tests on data to saving files downloaded from the internet. So where do packages fit into these tasks? From Quick-R{target="_blank"}: "Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library. R comes with a standard set of packages. Others are available for download and installation. Once installed, they have to be loaded into the session to be used."
Wasteload relevant functions are contained in two package: wqTools & wasteloadR. Package wqTools contains a set of useful functions that are commonly used and re-used in water quality analyses
(ex. converting units, loading calculations, and downloading data). wasteloadR contains the wasteload specific functions, gadgets, and applications.
These packages live on the Utah Division of Water Quality's GitHub{target="_blank"}.
GitHub is an online platform for storing, developing, and sharing a wide variety of computer languages. DWQ's GitHub page contains a number of repositories of R code used to perform water quality assessments and explore water quality data.
To install packages from GitHub, first install the devtools package from CRAN in R. To install the devtools package, type or copy/paste the code below into the R console and hit enter. Installing a package will also install any package dependencies.
install.packages("devtools")
A window may pop up asking you to select a CRAN repository. The "0-Cloud [https]" repository will suffice.
Load the devtools library to your workspace with the library() command. This will make all of the functions within the specified package available in your R session.
library(devtools)
To install packages from GitHub, use the devtools function install_github():
install_github("utah-dwq/wqTools", upgrade='never')
install_github("utah-dwq/wasteloadR", upgrade='never')
Note:
To avoid conflicting package versions and installations, I recommend updating package dependencies separately from GitHub package installs. To update local packages,
select Packages -> Update pacakges... from the R GUI menu bar or use update.packages(ask='graphics',checkBuilt=TRUE)
in the console.
You can then skip package dependency updates in install_github()
with the argument upgrade='never'
as above.
You do not need to perform the install_github() commands each time you wish to run the packages, only when when updates are desired.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.