Skip to content

Commit 6297335

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents 3493ee7 + 9b15669 commit 6297335

File tree

90 files changed

+3396
-446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3396
-446
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Imports:
7272
nhdplusTools,
7373
arcgislayers,
7474
httr,
75-
jsonlite
75+
jsonlite,
76+
rATTAINS
7677
Depends:
7778
R (>= 3.5.0)
7879
Suggests:
@@ -96,6 +97,6 @@ VignetteBuilder: knitr, rmarkdown
9697
Language: en-US
9798
Config/testthat/edition: 3
9899
Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)
99-
URL: https://usepa.github.io/EPATADA/, https://github.com/USEPA/EPATADA
100+
URL: https://usepa.github.io/EPATADA/, https://github.com/USEPA/EPATADA, usepa.github.io/EPATADA
100101
LazyData: true
101102
LazyDataCompression: xz

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ export(TADA_FlagSpeciation)
4040
export(TADA_FlaggedSitesMap)
4141
export(TADA_FormatDelimitedString)
4242
export(TADA_GetATTAINS)
43+
export(TADA_GetATTAINSAUSiteCrosswalk)
44+
export(TADA_GetATTAINSOrgIDsRef)
4345
export(TADA_GetActivityTypeRef)
4446
export(TADA_GetCharacteristicRef)
4547
export(TADA_GetDetCondRef)
4648
export(TADA_GetDetLimitRef)
4749
export(TADA_GetMeasureQualifierCodeRef)
4850
export(TADA_GetMeasureUnitRef)
51+
export(TADA_GetMonLocByOrgId)
4952
export(TADA_GetMonLocTypeRef)
5053
export(TADA_GetNutrientSummationRef)
5154
export(TADA_GetSynonymRef)
5255
export(TADA_GetTemplate)
5356
export(TADA_GetUSGSSynonymRef)
5457
export(TADA_GetUniqueNearbySites)
58+
export(TADA_GetWQPOrgProviderRef)
5559
export(TADA_GetWQXCharValRef)
5660
export(TADA_GroupedScatterplot)
5761
export(TADA_HarmonizeSynonyms)
@@ -77,6 +81,7 @@ export(TADA_SummarizeColumn)
7781
export(TADA_TribalOptions)
7882
export(TADA_TwoCharacteristicScatterplot)
7983
export(TADA_UniqueCharUnitSpeciation)
84+
export(TADA_UpdateMonitoringLocationsInATTAINS)
8085
export(TADA_ViewATTAINS)
8186
export(TADA_ViewColorPalette)
8287
export(TADA_addPoints)

R/ATTAINSRefTables.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#' ATTAINS Organization Identifier Reference Table
2+
#'
3+
#' Function downloads and returns the newest available crosswalk of state/tribe/territory codes
4+
#' and their respective organization names and organization identifiers.
5+
#'
6+
#' This function caches the table after it has been called once
7+
#' so subsequent calls will be faster.
8+
#'
9+
#' @return Updated sysdata.rda with updated ATTAINSOrgIDsRef object
10+
#'
11+
#' @export
12+
13+
TADA_GetATTAINSOrgIDsRef <- function() {
14+
# If there is a cached table available return it
15+
if (!is.null(ATTAINSOrgIDsRef_Cached)) {
16+
return(ATTAINSOrgIDsRef_Cached)
17+
}
18+
19+
# Try to download up-to-date raw data
20+
21+
raw.data <- tryCatch(
22+
{
23+
# get data from ATTAINS
24+
rATTAINS::domain_values(domain_name = "OrgName")
25+
},
26+
error = function(err) {
27+
NULL
28+
}
29+
)
30+
31+
# If the download failed fall back to internal data (and report it)
32+
if (is.null(raw.data)) {
33+
message("Downloading latest ATTAINS Organization Reference Table failed!")
34+
message("Falling back to (possibly outdated) internal file.")
35+
return(utils::read.csv(system.file("extdata", "ATTAINSOrgIDsRef.csv", package = "EPATADA")))
36+
}
37+
38+
ATTAINSOrgIDsRef <- raw.data %>%
39+
dplyr::distinct()
40+
41+
# Save updated table in cache
42+
ATTAINSOrgIDsRef_Cached <- ATTAINSOrgIDsRef
43+
44+
ATTAINSOrgIDsRef
45+
}
46+
47+
# Update ATTAINS Organization Identifier Reference Table
48+
# (for internal use only)
49+
50+
TADA_UpdateATTAINSOrgIDsRef <- function() {
51+
utils::write.csv(TADA_GetATTAINSOrgIDsRef(), file = "inst/extdata/ATTAINSOrgIDsRef.csv", row.names = FALSE)
52+
}
53+
54+
55+
# Used to store cached Measure Unit Reference Table
56+
ATTAINSOrgIDsRef_Cached <- NULL

R/CensoredDataSuite.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' the ResultMeasureValue field is populated with "ND" (indicating non-detect).
1717
#' In rare situations, new detection limit types are added to WQX domain tables
1818
#' (and thus WQP data) that have not yet been classified as over- or
19-
#' non-detects. When these appear in a data frame, they are categorized as
19+
#' non-detects. When these appear in a dataframe, they are categorized as
2020
#' "Detection condition or detection limit is not documented in TADA reference
2121
#' tables." In these situations, users should contact TADA administrators to
2222
#' update the package accordingly. This function is used by default in
@@ -165,18 +165,18 @@ TADA_IDCensoredData <- function(.data) {
165165
rm(nd.rmv.list)
166166

167167
## Let user know when detection condition text is missing from one or more results
168-
# NOTE that at this point, TADA.Detection_Type may be NA if there are detection conditions in data frame that are not present in domain table
168+
# NOTE that at this point, TADA.Detection_Type may be NA if there are detection conditions in dataframe that are not present in domain table
169169
if (any(cens$TADA.Detection_Type[!is.na(cens$TADA.Detection_Type)] == "ResultDetectionConditionText missing")) {
170170
missing_detcond <- length(cens$TADA.Detection_Type[cens$TADA.Detection_Type == "ResultDetectionConditionText missing"])
171-
print(paste0("TADA_IDCensoredData: There are ", missing_detcond, " results in your data frame that are missing ResultDetectionConditionText. TADA requires BOTH ResultDetectionConditionText and DetectionQuantitationLimitTypeName fields to be populated in order to categorize censored data."))
171+
print(paste0("TADA_IDCensoredData: There are ", missing_detcond, " results in your dataframe that are missing ResultDetectionConditionText. TADA requires BOTH ResultDetectionConditionText and DetectionQuantitationLimitTypeName fields to be populated in order to categorize censored data."))
172172
}
173173

174174
## Let user know when one or more result detection conditions are not in the ref table
175175
conds <- unique(cens$ResultDetectionConditionText[!is.na(cens$ResultDetectionConditionText)])
176176
if (any(!conds %in% cond.ref$ResultDetectionConditionText)) {
177177
missing_conds <- conds[!conds %in% cond.ref$ResultDetectionConditionText]
178178
missing_conds <- paste(missing_conds, collapse = ", ")
179-
print(paste0("TADA_IDCensoredData: ResultDetectionConditionText column in data frame contains value(s) ", missing_conds, " which is/are not represented in the ResultDetectionConditionText WQX domain table. These data records are placed under the TADA.CensoredData.Flag: Censored but not Categorized, and will not be used in censored data handling methods. Please contact TADA administrators to resolve."))
179+
print(paste0("TADA_IDCensoredData: ResultDetectionConditionText column in dataframe contains value(s) ", missing_conds, " which is/are not represented in the ResultDetectionConditionText WQX domain table. These data records are placed under the TADA.CensoredData.Flag: Censored but not Categorized, and will not be used in censored data handling methods. Please contact TADA administrators to resolve."))
180180
}
181181

182182
## Bring in det limit type reference table
@@ -191,7 +191,7 @@ TADA_IDCensoredData <- function(.data) {
191191
if (any(!limits %in% limtype.ref$DetectionQuantitationLimitTypeName)) {
192192
missing_lims <- limits[!limits %in% limtype.ref$DetectionQuantitationLimitTypeName]
193193
missing_lims <- paste(missing_lims, collapse = ", ")
194-
print(paste0("TADA_IDCensoredData: DetectionQuantitationLimitTypeName column in data frame contains value(s) ", missing_lims, " which is/are not represented in the DetectionQuantitationLimitTypeName WQX domain table. These data records are placed under the TADA.CensoredData.Flag: Censored but not Categorized, and will not be used in censored data handling methods. Please contact TADA administrators to resolve."))
194+
print(paste0("TADA_IDCensoredData: DetectionQuantitationLimitTypeName column in dataframe contains value(s) ", missing_lims, " which is/are not represented in the DetectionQuantitationLimitTypeName WQX domain table. These data records are placed under the TADA.CensoredData.Flag: Censored but not Categorized, and will not be used in censored data handling methods. Please contact TADA administrators to resolve."))
195195
}
196196

197197
## Create flag for condition and limit type combinations
@@ -236,15 +236,15 @@ TADA_IDCensoredData <- function(.data) {
236236

237237
if ("Detection condition or detection limit is not documented in TADA reference tables." %in% cens$TADA.CensoredData.Flag) {
238238
num <- length(cens$TADA.CensoredData.Flag[cens$TADA.CensoredData.Flag == "Detection condition or detection limit is not documented in TADA reference tables."])
239-
print(paste0("TADA_IDCensoredData: ", num, " records in the supplied data frame have detection conditions and/or limit types that are missing from TADA reference tables. These records will not be included in detection limit handling calculations."))
239+
print(paste0("TADA_IDCensoredData: ", num, " records in the supplied dataframe have detection conditions and/or limit types that are missing from TADA reference tables. These records will not be included in detection limit handling calculations."))
240240
}
241241

242242
cens <- cens %>% dplyr::select(-TADA.Detection_Type, -TADA.Limit_Type, -TADA.MeasureQualifierCode.Flag)
243243

244244
cens.check <- plyr::rbind.fill(cens, not_cens)
245245
} else {
246246
cens.check <- not_cens
247-
print("TADA_IDCensoredData: No censored data detected in your data frame. Returning input dataframe with new column TADA.CensoredData.Flag set to Uncensored")
247+
print("TADA_IDCensoredData: No censored data detected in your dataframe. Returning input dataframe with new column TADA.CensoredData.Flag set to Uncensored")
248248
}
249249

250250
cens.check <- TADA_OrderCols(cens.check)
@@ -258,7 +258,7 @@ TADA_IDCensoredData <- function(.data) {
258258
#' before applying simple tools for non-detect and over-detect data handling, including filling
259259
#' in the values as-is, X times the detection limit, or a random number between 0
260260
#' and the LOWER detection limit. These methods do NOT depend upon censored data frequency
261-
#' in the data frame.
261+
#' in the dataframe.
262262
#'
263263
#' This function runs TADA_IDCensoredData within it which adds the column
264264
#' TADA.CensoredData.Flag. Enter ?TADA_IDCensoredData into the console for more
@@ -281,7 +281,7 @@ TADA_IDCensoredData <- function(.data) {
281281
#' @export
282282
#'
283283
#' @examples
284-
#' # Load example data frame:
284+
#' # Load example dataframe:
285285
#' data(Data_Nutrients_UT)
286286
#' # Check for agreement between detection condition and detection limit type,
287287
#' # and in instances where the measurement is non-detect, set the result value
@@ -328,7 +328,7 @@ TADA_SimpleCensoredMethods <- function(.data, nd_method = "multiplier", nd_multi
328328
}
329329

330330
if (all(cens.data$TADA.CensoredData.Flag == "Uncensored")) {
331-
print("Cannot apply simple censored methods to data frame with no censored data results. Returning input data frame.")
331+
print("Cannot apply simple censored methods to dataframe with no censored data results. Returning input dataframe.")
332332
.data <- cens.data
333333
} else {
334334
# split out over detects and non detects

R/CriteriaComparison.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#' Create Reference Data Frame to Pair Characteristic Results For Use in Numeric Criteria Equations (UNDER ACTIVE DEVELOPMENT)
1+
#' Create Reference Dataframe to Pair Characteristic Results For Use in Numeric Criteria Equations (UNDER ACTIVE DEVELOPMENT)
22
#'
3-
#' This function creates a data frame that shows all combinations of TADA.CharacteristicName,
3+
#' This function creates a dataframe that shows all combinations of TADA.CharacteristicName,
44
#' TADA.CharacteristicName, TADA.ResultMeasure.MeasureUnitCode, TADA.MethodSpeciationName,
55
#' and TADA.ResultSampleFractionText for commonly paired characteristics (such as pH, temperature,
66
#' hardness, salinity, and chloride).
77
#'
88
#' @param .data TADA dataframe
99
#'
10-
#' @param ph Boolean argument. When ph = TRUE, pH is included in this reference data frame. When
11-
#' ph = FALSE, pH is not included in the reference data frame.
10+
#' @param ph Boolean argument. When ph = TRUE, pH is included in this reference dataframe. When
11+
#' ph = FALSE, pH is not included in the reference dataframe.
1212
#'
1313
#' @param hardness Boolean argument. When hardness = TRUE, hardness is included in this reference
14-
#' data frame. When hardness = FALSE, hardness is not included in the reference data frame.
14+
#' dataframe. When hardness = FALSE, hardness is not included in the reference dataframe.
1515
#'
1616
#' @param temp Boolean argument. When temp = TRUE, water temperature is included in this reference
17-
#' data frame. When temp = FALSE, water temperature is not included in the reference data frame.
17+
#' dataframe. When temp = FALSE, water temperature is not included in the reference dataframe.
1818
#'
1919
#' @param salinity Boolean argument. When salinity = TRUE, salinity is included in this reference
20-
#' data frame. When salinity = FALSE, salinity is not included in the reference data frame.
20+
#' dataframe. When salinity = FALSE, salinity is not included in the reference dataframe.
2121
#'
2222
#' @param chloride Boolean argument. When chloride = TRUE, salinity is included in this reference
23-
#' data frame. When chloride = FALSE, chloride is not included in the reference data frame.
23+
#' dataframe. When chloride = FALSE, chloride is not included in the reference dataframe.
2424
#'
25-
#' @param other_char Character argument. The user provides a data frame TADA.CharacteristicNames and
25+
#' @param other_char Character argument. The user provides a dataframe TADA.CharacteristicNames and
2626
#' the pairing group they belong to. #Needs more details.
2727
#
28-
#' @return A data frame with six columns, TADA.CharacteristicName, TADA.ResultMeasure.MeasureUnitCode,
28+
#' @return A dataframe with six columns, TADA.CharacteristicName, TADA.ResultMeasure.MeasureUnitCode,
2929
#' TADA.MethodSpeciationName, TADA.ResultSampleFractionText, TADA.PairingGroup, and
3030
#' TADA.PairingGroupRank.
3131
#'
@@ -40,7 +40,7 @@
4040
#'
4141
TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
4242
chloride = TRUE, salinity = TRUE, other_char = "null") {
43-
# create data frame to store pair refs
43+
# create dataframe to store pair refs
4444
pair.ref <- data.frame(matrix(ncol = 6, nrow = 0))
4545

4646
# name columns in pair.ref df
@@ -155,7 +155,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
155155
}
156156

157157
if (!is.data.frame(other_char) & other_char != "null") {
158-
stop("TADA_CreatePairRef: 'other_char' must be a data frame with three columns. The first column
158+
stop("TADA_CreatePairRef: 'other_char' must be a dataframe with three columns. The first column
159159
contains TADA.CharacteristicName, the second column contains TADA.PairingGroup, and the
160160
third column contains TADA.PairingGroup.Rank")
161161
}
@@ -172,7 +172,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
172172
# check to see if there are any rows in pair.ref
173173

174174
if (nrow(pair.ref) == 0) {
175-
stop("None of the specified pairing characteristics were found in the TADA data frame.")
175+
stop("None of the specified pairing characteristics were found in the TADA dataframe.")
176176
}
177177

178178
return(pair.ref)
@@ -183,7 +183,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
183183
#' This function pairs TADA results with results from specified characteristics from the same
184184
#' MonitoringLocation within a user-specified time window to facilitate the calculation of numeric
185185
#' criteria. The columns created by TADA_AutoClean are required to run this function. If they are not
186-
#' present in the data frame, the function will stop and print an error message.
186+
#' present in the dataframe, the function will stop and print an error message.
187187
#'
188188
#' Users can provide a pairing reference file (can be created using TADA_CreatePairRef) to specify
189189
#' which combinations of TADA.CharacteristicName, TADA.ResultMeasure.MeasureUnit,
@@ -198,7 +198,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
198198
#' @param hours_range Numeric argument. The time difference allowed between the paired characteristic
199199
#' and the result.
200200
#
201-
#' @return A TADA data frame with six additional columns added for each pairing group specified
201+
#' @return A TADA dataframe with six additional columns added for each pairing group specified
202202
#' in the pairing ref.
203203
#' @export
204204
#'
@@ -217,7 +217,7 @@ TADA_PairForCriteriaCalc <- function(.data, ref = "null", hours_range = 4) {
217217
# check to see if user-supplied ref is a df
218218
if (!is.character(ref)) {
219219
if (!is.data.frame(ref)) {
220-
stop("TADA_PairForCriteriaCalc: 'ref' must be a data frame with six columns: TADA.CharacteristicName,
220+
stop("TADA_PairForCriteriaCalc: 'ref' must be a dataframe with six columns: TADA.CharacteristicName,
221221
TADA.ResultMeasure.MeasureUnitCode, TADA.MethodSpeciationName, TADA.ResultSampleFractionText,
222222
TADA.PairingGroup.Rank, and TADA.PairingGroup.")
223223
}
@@ -232,7 +232,7 @@ TADA_PairForCriteriaCalc <- function(.data, ref = "null", hours_range = 4) {
232232
ref.names <- names(ref)
233233

234234
if (length(setdiff(col.names, ref.names)) > 0) {
235-
stop("TADA_PairForCriteriaCalc: 'ref' must be a data frame with six columns: TADA.CharacteristicName,
235+
stop("TADA_PairForCriteriaCalc: 'ref' must be a dataframe with six columns: TADA.CharacteristicName,
236236
TADA.ResultMeasure.MeasureUnitCode, TADA.MethodSpeciationName, TADA.ResultSampleFractionText,
237237
TADA.PairingGroup.Rank, and TADA.PairingGroup.")
238238
}

0 commit comments

Comments
 (0)