Skip to contents

This function pulls in all prior ATTAINS Use names associated with each ATTAINS organization's Assessment Unit (AU) from the prior ATTAINS cycle. This function requires an ATTAINS org_id and a crosswalk of an organization's WQP Monitoring Location's, ATTAINS Assessment Unit's, and ATTAINS Water Type codes as a function input (AUMLRef). The output from TADA_CreateATTAINSAUMLCrosswalk(.data, return_sf = FALSE) can be used directly as the AUMLRef argument input in this function. Alternatively, a user supplied crosswalk can be entered or TADA_GetATTAINSAUMLCrosswalk() and/or TADA_UpdateATTAINSAUMLCrosswalk() functions can be leveraged to generate the crosswalk.

Usage

TADA_CreateUseAURef(
  .data,
  org_id = NULL,
  AUMLRef = NULL,
  useAURef = NULL,
  waterUseRef = NULL,
  excel = FALSE,
  overwrite = FALSE
)

Arguments

.data

A TADA dataframe. The user should run all desired data cleaning, processing, harmonization, filtering, and handling of censored data functions prior to running this function.

org_id

The ATTAINS organization identifier must be supplied by the user. A list of organization identifiers can be found by downloading the ATTAINS Domains Excel file: https://www.epa.gov/system/files/other-files/2025-02/domains_2025-02-25.xlsx. organization identifiers are listed in the "OrgName" tab. The "code" column contains the organization identifiers that should be used for this param. If a user does not provide an org_id argument, the function attempts to identify which organization identifier(s) to include based on the unique ATTAINS organization identifiers found in the dataframe.

AUMLRef

A required data frame input. This data frame should contain a completed crosswalk of WQP Monitoring Locations associated with each ATTAINS Assessment Unit. Users will need to ensure this crosswalk contains the appropriate column names in order to run this function. See module 2 vignette and sample output of TADA_CreateATTAINSAUMLCrosswalk().

useAURef

An optional data frame input. If provided, this data frame should contain a completed crosswalk of use names associated with each assessment unit. Users will need to ensure this crosswalk contains the appropriate column names in order to run the function.

waterUseRef

An optional data frame input. If provided, this data frame should contain a completed crosswalk of use names associated with a water type. Users will need to ensure this crosswalk contains the appropriate column names in order to run the function.

excel

A Boolean value that returns an excel spreadsheet if excel = TRUE. This spreadsheet is created in the user's downloads folder path. If you have any trouble locating the file, please type the following into your R console to locate it: file.path(Sys.getenv("USERPROFILE"), "Downloads"). The file will be named "myfileRef.xlsx". The excel spreadsheet will highlight the cells in which users should input information.

overwrite

A Boolean value that ensures the function will not overwrite the user supplied crosswalk entered into this function via the paramRef function input. This helps prevent users from overwriting their progress.

Value

A data frame with all the MonitoringLocationIdentifier Sites for each defined AU.

Details

This function is mainly designed to assist with pulling existing Uses that have been entered into ATTAINS in the prior ATTAINS cycle (most recent assessment).

For any NEW AUs and/or NEW uses, users must modify the output of this function to manually add those uses and AU's to the crosswalk. Alternatively, we have developed a helper function, TADA_CreateWaterUseRef(), to assist with assigning uses to NEW AU's. This can be leveraged to assign uses for any new AUs based on the water type of the AU. Users can either supply their own Water Type to Use crosswalk or utilize ATTAINS webservices to pull in the Water Type to Use reference file. This Water to Use reference file can be used to assign all unique Uses to a new/modified AU based on which uses have been assigned to that water type in the past for the specified ATTAINS organization. Any new or modified AU and use information that gets submitted to ATTAINS in the current assessment cycle will not be available in ATTAINS until the assessment is approved and completed.

See also

TADA_DataRetrieval() for the required format of .data

TADA_CreateATTAINSAUMLCrosswalk() to help generate the required AUMLRef

TADA_GetATTAINSAUMLCrosswalk() to help generate the required AUMLRef

TADA_UpdateATTAINSAUMLCrosswalk() to help generate the required AUMLRef

TADA_CreateWaterUseRef() to help assign ATTAINS Uses to NEW ATTAINS Assessment Units based on ATTAINS Water Type

Examples

if (FALSE) { # \dontrun{
# Pull a sample WQP data query
TADA_AK_Example <- TADA_DataRetrieval(
  startDate = "2022-01-01", endDate = "2022-12-31",
  organization = "AKDECWQ", statecode = "AK",
  characteristicName = c("Enterococcus", "Escherichia", "Escherichia coli"),
  ask = FALSE
)

# Alaska example to update data links with no user supplied crosswalk
AK_adddatalinks <- TADA_UpdateATTAINSAUMLCrosswalk(
  org_id = "AKDECWQ",
  crosswalk = NULL,
  attains_replace = FALSE,
  wqp_data_links = "replace"
)

# Alaska example using a user supplied crosswalk to update entries in
# ATTAINS by appending user supplied information to ATTAINS crosswalk

# example new AU identifiers
ATTAINS.AssessmentUnitIdentifier <- c(
  "NEW:AK_M_1021211_000", "NEW:AK_M_1021008_000",
  "NEW:AK_M_1021109_013", "NEW:AK_L_2040108_063",
  "NEW:AK_M_1021109_013"
)

# example organization identifiers
ATTAINS.OrganizationIdentifier <-
  c("AKDECWQ", "AKDECWQ", "AKDECWQ", "AKDECWQ", "AKDECWQ")

# example ML matched to new AUs, these are only examples
ATTAINS.MonitoringLocationIdentifier <- c(
  "AKDECWQ-Snag Point", "AKDECWQ-Kanakanak", "AKDECWQ-ANC02_HSLP",
  "AKDECWQ-Scandinavian", "AKDECWQ-ANC03_HSLP"
)

ATTAINS.WaterType <- c(
  "BEACH", "BAY", "CREEK",
  "ESTUARY", "CREEK"
)

# create example crosswalk data frame
ex.user.cw <- data.frame(
  ATTAINS.MonitoringLocationIdentifier,
  ATTAINS.OrganizationIdentifier,
  OrganizationIdentifier = ATTAINS.OrganizationIdentifier,
  ATTAINS.AssessmentUnitIdentifier,
  ATTAINS.MonitoringDataLinkText = NA, ATTAINS.WaterType
)

AK_appenduserdata <- TADA_UpdateATTAINSAUMLCrosswalk(
  org_id = "AKDECWQ",
  crosswalk = ex.user.cw,
  attains_replace = FALSE,
  wqp_data_links = "replace"
)

# New AUs that are not found in ATTAINS show blank ATTAINS.UseName
AK_CreateUseAURef <- TADA_CreateUseAURef(
  TADA_AK_Example,
  org_id = "AKDECWQ",
  AUMLRef = AK_appenduserdata,
  excel = FALSE
)

# Let's use a wateruseRef now to fill in these values.
AK_CreateUseAURef_auto_assign <- TADA_CreateUseAURef(
  TADA_AK_Example,
  org_id = "AKDECWQ",
  AUMLRef = AK_appenduserdata,
  waterUseRef = TADA_CreateWaterUseRef(TADA_AK_EXAMPLE, org_id = "AKDECWQ"),
  excel = FALSE
)

# We can save and reuse a useAURef as desired.
AK_CreateUseAURef2 <- TADA_CreateUseAURef(
  TADA_AK_Example,
  org_id = "AKDECWQ",
  useAURef = AK_CreateUseAURef_auto_assign,
  AUMLRef = AK_appenduserdata,
  excel = FALSE
)
} # }