Example Module 2 Workflow
TADA Team
2025-08-21
Source:vignettes/ExampleMod2Workflow.Rmd
ExampleMod2Workflow.Rmd
Install and Load EPATADA Package
First, install and load the remotes package specifying the repo. This is needed before installing EPATADA because it is only available on GitHub (not CRAN).
install.packages("remotes",
repos = "http://cran.us.r-project.org"
)
library(remotes)
Next, install and load EPATADA using the remotes package. USGS’s dataRetrieval and other TADA R Package dependencies will also be downloaded automatically from CRAN with the TADA install. If desired, the development version of dataRetrieval can be downloaded directly from GitHub (un-comment).
remotes::install_github("USEPA/EPATADA",
ref = "develop",
dependencies = TRUE
)
# remotes::install_github("USGS-R/dataRetrieval", dependencies=TRUE)
Finally, use the library() function to load the TADA R Package into your R session.
Get WQP Monitoring Data in Montana Using TADA_DataRetrieval()
Get bacteria and pH data from Missoula County, Montana.
# get MT data
tada.MT <- TADA_DataRetrieval(
startDate = "2020-01-01",
endDate = "2022-12-31",
statecode = "MT",
characteristicName = c("Escherichia",
"Escherichia coli",
"pH"),
county = "Missoula County",
ask = FALSE)
# clean up data set (minimal)
tada.MT.clean <- tada.MT %>%
TADA_RunKeyFlagFunctions() %>%
TADA_SimpleCensoredMethods()
# remove intermediate objects
rm(tada.MT)
Create An Example User-Supplied ATTAINS Assessment Unit and WQP Monitoring Location Crosswalk
Get existing data from ATTAINS and subset a few rows to create an example user-supplied crosswalk for demonstration purposes.
Find Additional ATTAINS Assessment Unit and WQP Monitoring Location Matches Using TADA_CreateAUMLCrosswalk()
Run TADA_CreateAUMLCrosswalk which can incorporate any combination of:
(optional) user-supplied crosswalk,
crosswalk downloaded from ATTAINS, and
results from TADA_CreateATTAINSAUMLCrosswalk which leverages the ATTAINS catchments to join monitoring locations to assessment units via a geospatial join .
The assignments are prioritized in the order listed. Any WQP monitoring locations which remain unassigned after checking the user-supplied crosswalk will be subset and run with TADA_CreateATTAINSAUMLCrosswalk which will attempt to make additional ATTAINS assessment unit assignments.
To make this function run more efficiently, and because we already have assessment unit assignments for some monitoring locations from the user-supplied crosswalk and the crosswalk downloaded from ATTAINS, the ATTAINS catchment data from the geospatial service is not currently being returned for matches in the crosswalks supplied by users or imported from ATTAINS. We have plans to create additional functions/internal reference files to facilitate this returning the associated catchments in the future. Therefore, any catchment data available for mapping is currently from TADA_CreateATTAINSAUMLCrosswalk assessed WQP monitoring locations only.
# use TADA get attains to make AU assignments for unassigned MLs
MT.AUMLRef <- TADA_CreateAUMLCrosswalk(tada.MT.clean,
au_ref = user.supplied.cw,
org_id = "MTDEQ",
add_catch = FALSE,
batch_upload = TRUE)
Generate a Map with TADA_ViewATTAINS
The TADA_ViewATTAINS() map function shows the results from all three different crosswalk sources (user supplied crosswalk, ATTAINS crosswalk, and ATTAINS catchments/geospatial join) using different color circle markers (not final colors, we are very open to suggestions). The source has also been added to the popup window.
TADA_ViewATTAINS(MT.AUMLRef)
TADA_UpdateATTAINSAUMLCrosswalk
After making any necessary changes to the ATTAINS_batchupload data frame generated by TADA_CreateAUMLCrosswalk, run TADA_UpdateATTAINSAUMLCrosswalk to add new links to WQP site pages.
batch.upload.MT <- MT.AUMLRef$ATTAINS_batchupload %>%
TADA_UpdateATTAINSAUMLCrosswalk(# selected attains_replace = TRUE because all matches currently in ATTAINS are included in this new crosswalk
attains_replace =TRUE,
batch_upload = TRUE,
wqp_data_links = "add",
#ml ids have already been corrected if needed
update_mlid = FALSE,
org_id = "MTDEQ")