Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Utilities.R #365

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading