Create or Update Monitoring Location Identifier and Assessment Unit Identifier Crosswalk in ATTAINS
Source:R/ATTAINSCrosswalks.R
TADA_UpdateMonitoringLocationsInATTAINS.Rd
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_UpdateMonitoringLocationsInATTAINS(
org_id = NULL,
crosswalk = NULL,
attains_replace = FALSE,
wqp_data_links = "add"
)
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/2023-09/DOMAINS.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 ASSESSMENT_UNIT_ID, MS_LOCATION_ID, MS_ORG_ID, and MONITORING_DATA_LINK_TEXT is required. The ASSESSMENT_UNIT_ID and MS_LOCATION_ID must be filled out in order to use this function. The additional columns, MONITORING_DATA_LINK_TEXT, containing a single URL or "; " separated URLs linking to information about the monitoring location, and MS_ORG_ID, 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 MS_ORG_ID 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.
- wqp_data_links
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. It will examine the response code of each URL and only retain those with a 200 response, which indicates the URL is valid. 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".
Value
A dataframe with four columns, MonitoringLocationIdentifier, OrganizationIdentifier, ATTAINS.assessmentunitidentifier, and MonitoringDataLinkText is returned. This matches the format of the batch upload files required to add or update monitoring locations in ATTAINS.
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_UpdateMonitoringLocationsInATTAINS(
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 monitoring location identifiers
ASSESSMENT_UNIT_ID <- c(
"AK_M_1021211_000", "AK_M_1021008_000",
"AK_M_1021109_013", "AK_M_1021109_013",
"AK_M_1021109_013"
)
# example organization identifiers
MS_ORG_ID <- c("AKDECWQ", "AKDECWQ", "AKDECWQ", "AKDECWQ", "AKDECWQ")
# example assessment units
MS_LOCATION_ID <- c(
"ExampleSite1", "ExampleSite2", "ExampleSite3",
"ExampleSite4", "ExampleSite5"
)
# example urls
MONITORING_DATA_LINK_TEXT <- 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(
MS_LOCATION_ID, MS_ORG_ID, ASSESSMENT_UNIT_ID,
MONITORING_DATA_LINK_TEXT
)
AK_appenduserdata <- TADA_UpdateMonitoringLocationsInATTAINS(
org_id = "AKDECWQ",
crosswalk = ex.user.cw,
attains_replace = FALSE,
wqp_data_links = "none"
)
} # }