Skip to content

Commit

Permalink
Merge pull request #365 from USEPA/307-retired-characteristic-names
Browse files Browse the repository at this point in the history
Update Utilities.R
  • Loading branch information
cristinamullin authored Dec 7, 2023
2 parents 7695d3f + 101080f commit 6089220
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ TADA_OrderCols <- function(.data) {
#' in TADA_BigDataRetrieval. Therefore, deprecated characteristic names are
#' harmonized to their current name automatically upon data retrieval.
#' TADA_SubstituteDeprecatedChars can also be used by itself on a user supplied
#' dataset that is in the WQX format, if desired.
#' dataset that is in the WQX format, if desired. This solution works for both EPA WQX and USGS NWIS provided data.
#'
#' @param .data TADA dataframe
#'
Expand All @@ -624,9 +624,23 @@ TADA_OrderCols <- function(.data) {
TADA_SubstituteDeprecatedChars <- function(.data) {
TADA_CheckColumns(.data, expected_cols = c("CharacteristicName", "TADA.CharacteristicName"))

# read in characteristic reference table with deprecation information and filter to deprecated terms
ref.table <- TADA_GetCharacteristicRef() %>% dplyr::filter(Char_Flag == "Deprecated")

# read in characteristic reference table with deprecation information, filter to deprecated terms and for "retired" in CharactersticName.
# remove all characters after first "*" in CharacteristicName and remove any leading or trailing white space to make compatible with deprecated NWIS CharactersticName.
nwis.table <- TADA_GetCharacteristicRef() %>%
dplyr::filter(
Char_Flag == "Deprecated",
grepl("retired", CharacteristicName)
) %>%
dplyr::mutate(CharacteristicName = trimws(stringr::str_split(CharacteristicName, "\\*", simplify = T)[, 1]))

# read in characteristic reference table with deprecation information and filter to deprecated terms.
# join with deprecated NWIS CharacteristicName data.frame.
ref.table <- TADA_GetCharacteristicRef() %>%
dplyr::filter(Char_Flag == "Deprecated") %>%
rbind(nwis.table)

rm(nwis.table)

# merge to dataset
.data <- merge(.data, ref.table, all.x = TRUE)
# if CharacteristicName is deprecated and comparable name is not BLANK, use the provided Comparable.Name. Otherwise, keep TADA.CharacteristicName as-is.
Expand Down

0 comments on commit 6089220

Please sign in to comment.