Skip to contents

This function creates the batch upload files needed to create or update Monitoring Location Identifiers in ATTAINS Assessment Unit profiles. Users can specify whether all records should be overwritten (replaced) or if new Monitoring Location Identifiers should be appended (added) to existing records.

Usage

TADA_UpdateATTAINSAUMLCrosswalk(
  org_id = NULL,
  crosswalk = NULL,
  attains_replace = FALSE,
  wqp_data_links = "add",
  update_mlid = TRUE,
  batch_upload = FALSE,
  check_links = FALSE
)

Arguments

org_id

Character argument. 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.

crosswalk

A user-supplied dataframe with the columns ATTAINS.MonitoringLocationIdentifier, OrganizationIdentifier, ATTAINS.WaterType, ATTAINS.AssessmentUnitIdentifier, and ATTAINS.MonitoringDataLinkText is required. The ATTAINS.AssessmentUnitIdentifier and ATTAINS.MonitoringLocationIdentifier must be filled out in order to use this function. The additional columns, ATTAINS.MonitoringDataLinkText, containing a single URL or "; " separated URLs linking to information about the monitoring location, and OrganizationIdentifier, containing the WQP organization identifier for the monitoring location can be left blank and the function will still run. Data link URLS to WQP site pages cannot be automatically generated by this function unless the OrganizationIdentifier column is populated with the WQP OrganizationIdentifier. When crosswalk = NULL, the crosswalk will be downloaded from ATTAINS. This allows users to add URLs for the Water Quality Portal data site pages to the ATTAINS assessment unit profile where possible without updating other information in ATTAINS.

attains_replace

Character argument. When attains_replace = FALSE, all Monitoring Location Identifiers in the user supplied crosswalk will be appended to the existing ATTAINS crosswalk. When attains_replace = TRUE, Monitoring Location Identifiers will only be retained if they are in the user supplied crosswalk. Default equals FALSE.

Character argument. When wqp_data_links is equal to "add" or "replace", the function will build the URL for the Water Quality Portal Data Site page for each Monitoring Location Identifier in the data frame. When wqp_data_links = "add", the URL will be added to any existing text in the MS_DATA_LINK_TEXT column. When wqp_data_links = "replace", the URL will replace any existing text in the MS_DATA_LINK_TEXT column. When wqp_data_links = "none", no URLs will be created or added to the returned data frame. Default is wqp_data_links = "add".

update_mlid

Boolean argument. Updates MonitoringLocationIdentifier to be compatible with WQP MonitoringLocationIdentifiers by adding prefix for provider and organization identifier if needed when update_mlid = TRUE. Default is update_mlid = TRUE.

batch_upload

Boolean argument. When batch_upload = TRUE, the column names in the returned df will match the column names required for ATTAINS batch upload. When batch_upload = FALSE, the column names will match those in the TADA workflow. Default is batch_upload = FALSE.

Boolean argument. When check_links = TRUE the function will examine the response code of each MS_DATA_LINK URL and only retain those with a 200 response, which indicates the URL is valid.

Value

When batch_upload = FALSE, A dataframe with six columns: OrganizationIdentifier, ATTAINS.OrganizationIdentifier, ATTAINS.MonitoringLocationIdentifier, ATTAINS.AssessmentUnitIdentifier, ATTAINS.MonitoringDataLinkText, ATTAINS.WaterType is returned. When batch_upload = TRUE, A dataframe with four columns: MS_ORG_ID, MS_LOCATION_ID, ASSESSMENT_UNIT_ID, MS_DATA_LINK is returned. This is the crosswalk between monitoring location identifiers and assessment units that the state or tribal organization submitted to ATTAINS (optional).

Details

ATTAINS batch upload files are available here: https://www.epa.gov/waterdata/upload-data-resources-registered-attains-users#batch-upload-templates See Assessment Unit Batch Upload Template.

Examples

if (FALSE) { # \dontrun{
# Alaska example to updated 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 assessment unit identifiers
ATTAINS.AssessmentUnitIdentifier <- c(
  "AK_M_1021211_000", "AK_M_1021008_000",
  "AK_M_1021109_013", "AK_M_1021109_013",
  "AK_M_1021109_013"
)

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

# example monitoring location identifiers
ATTAINS.MonitoringLocationIdentifier <- c(
  "ExampleSite1", "ExampleSite2", "ExampleSite3",
  "ExampleSite4", "ExampleSite5"
)

# example water types
ATTAINS.WaterType <- c(
  "BEACH", "BAY", "CREEK",
  "ESTUARY", "CREEK"
)

# example urls
ATTAINS.MonitoringDataLinkText <- c(
  "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/",
  "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/",
  "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/",
  "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/",
  "https://www.waterqualitydata.us/provider/STORET/AKDECWQ/"
)

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

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