Introduction"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = TRUE
)
## setup vcr not sure I am doing this right.
library(vcr)
invisible(vcr::vcr_configure(
  dir = "../tests/fixtures",
  write_disk_path = NULL
))

About

The Assessment, Total Maximum Daily Load (TMDL) Tracking and Implementation System (ATTAINS) is the U.S. Environmental Protection Agency (EPA) database used to track information provided by states about water quality assessments conducted under the Clean Water Act. The assessments are conducted every two years to evaluate if the nation's water bodies meet water quality standards. States are required to take Actions (TMDLs or other efforts) on water bodies that do not meet standards. Public information in ATTAINS is made available through webservices and provided as JSON files. rATTAINS facilitates accessing this data with various functions that provide raw JSON or formatted "tidy" data for each of the ATTAINS webservice endpoints. More information about Clean Water Act assessment and reporting is available through the EPA. For alternative methods of accessing the same data, see "How's My Waterway" webpage for interactive data exploration or the ArcGIS MapService for spatial data.

Functions

Summary Services

The EPA provides two summary service endpoint that provide summaries of assessed uses by the organization identifier or by hydrologic unit code (HUC). For example, to return a summary of assessed uses by the state of Tennessee the following function is used:

vcr::insert_cassette("state_summary")
library(rATTAINS)
x <- state_summary(organization_id = "TDECWR",
                   reporting_cycle = "2016")
x
vcr::eject_cassette("state_summary")

The HUC12 service operates similarly but provides data summarized by area, specifically HUC12 units. For example:

vcr::insert_cassette("huc12_works")
x <- huc12_summary("020700100204")
x
vcr::eject_cassette("huc12_works")

huc12_summary() returns a list of tibbles with different summaries of information. Using the above example: - x$huc_summary provides a summary of HUC area, and the area and percentage of catchment assessed as good, unknown, or impaired. - x$au_summary provides a tibble with the unique identifiers for the assessment units (or distinct sections of waterbodies) within the queried HUC12. - x$ir_summary provides a simple summary of the area of the catchment classified under different Integrated Report Categories. - x$status_summary provides a summary of the overall status within the HUC12. - x$use_group_summary provides a summary of use attainment bu use group within the HUC12. - x$use_summary breaks the use summary down further by the use name. - x$param_summary provides the same information for parameter groups. - x$res_plan_summary and x$vision_plan_summary provides a summary of the amount of the watershed covered by particular types of restoration plans or vision plan, such as TMDLs.

Domains

Each function has a number of allowable arguments and associated values. In order to explore what values you might be interested in querying, the Domain Value service provides information about allowable options. This is mapped to the domain_values() function. When used without any arguments you get a full list of possible "domains." These are typically searchable parameters used in all the functions in rATTAINS. Note that the domain names returned by these service are not a one to one match with the argument names used in rATTAINS. It is typically fairly easy to figure out which ones match up to which arguments.

For example if I want to find out the possible organization identifiers to query by:

vcr::insert_cassette("single_domain")
x <- domain_values(domain_name = "OrgStateCode")
x
vcr::eject_cassette("single_domain")

The function returns a variable with the state codes and the possible parameter values as the context variable. Similarly if I want to look up possible Use Names that are utilized by the Texas Commission on Environmental Quality:

vcr::insert_cassette("domains_works")
x <- domain_values(domain_name = "UseName", context = "TCEQMAIN")
x
vcr::eject_cassette("domains_works")

Other Services

JSON Files

By default, all the functions rATTAINS return one or more "tidy" dataframes. These dataframe are created by attempting to flatten the nested JSON data returned by the webservice. This does require some opinionated decisions on what constitutes flat data, and at what variable data should be flattened to. We recognize that the dataframe output might not meet user needs. There if you would prefer to parse the JSON data yourself, use the tidy=FALSE argument to return an unparsed JSON string. A number of R packages are available to parse and flatten JSON data to prepare it for analysis.

Notes

The U.S. EPA is the data provider for this public information. rATTAINS and the author are not affiliated with the EPA. Questions about the package functionality should be directed to the package author. Questions about the webservice or underlying data should be directed to the U.S. EPA. Please do not abuse the webservice using this package.



Try the rATTAINS package in your browser

Any scripts or data that you put into this service are public.

rATTAINS documentation built on April 25, 2023, 5:10 p.m.