Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ Suggests:
spelling,
htmltools,
tigris,
yaml,
remotes
yaml
Remotes:
DOI-USGS/dataRetrieval@develop
VignetteBuilder: knitr, rmarkdown
Expand Down
30 changes: 15 additions & 15 deletions R/ATTAINSCrosswalks.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,14 @@ TADA_UpdateMonitoringLocationsInATTAINS <- function(org_id = NULL,
#' # See below for a simple example of this workflow:
#'
#' # Manually add ATTAINS parameters to crosswalk using R
#' paramRef_UT2 <- dplyr::mutate(paramRef_UT,
#' ATTAINS.ParameterName = dplyr::case_when(
#' grepl("AMMONIA", TADA.ComparableDataIdentifier) ~ "AMMONIA, TOTAL",
#' grepl("NITRATE", TADA.ComparableDataIdentifier) ~ "NITRATE",
#' grepl("NITROGEN", TADA.ComparableDataIdentifier) ~
#' "NITRATE/NITRITE (NITRITE + NITRATE AS N)"
#' ))
#' paramRef_UT2 <- dplyr::mutate(paramRef_UT,
#' ATTAINS.ParameterName = dplyr::case_when(
#' grepl("AMMONIA", TADA.ComparableDataIdentifier) ~ "AMMONIA, TOTAL",
#' grepl("NITRATE", TADA.ComparableDataIdentifier) ~ "NITRATE",
#' grepl("NITROGEN", TADA.ComparableDataIdentifier) ~
#' "NITRATE/NITRITE (NITRITE + NITRATE AS N)"
#' )
#' )
#' # Update the 'ATTAINS.FlagParameterName' values
#' paramRef_UT3 <- TADA_CreateParamRef(Data_Nutrients_UT,
#' paramRef = paramRef_UT2,
Expand All @@ -570,8 +571,8 @@ TADA_UpdateMonitoringLocationsInATTAINS <- function(org_id = NULL,
#' # Example where multiple org_id's are selected
#' # First, run key flag functions and harmonize synonyms across
#' # characteristic, fraction, and speciation columns
#' Data_NCTCShepherdstown <-
#' TADA_RunKeyFlagFunctions(Data_NCTCShepherdstown_HUC12)
#' Data_NCTCShepherdstown <-
#' TADA_RunKeyFlagFunctions(Data_NCTCShepherdstown_HUC12)
#' Data_NCTCShepherdstown2 <- TADA_HarmonizeSynonyms(Data_NCTCShepherdstown)
#' # Create ATTAINS parameter crosswalk for MD, VA, and PA
#' paramRef_NCTC <- TADA_CreateParamRef(Data_NCTCShepherdstown2,
Expand Down Expand Up @@ -742,7 +743,7 @@ TADA_CreateParamRef <- function(.data, org_id = NULL, paramRef = NULL, excel = T
)
) %>%
dplyr::select(
TADA.ComparableDataIdentifier, organization_identifier,
TADA.ComparableDataIdentifier, organization_identifier,
EPA304A.PollutantName, ATTAINS.ParameterName
) %>%
dplyr::filter(organization_identifier %in% org_id) %>%
Expand Down Expand Up @@ -1338,7 +1339,7 @@ TADA_CreateUseParamRef <- function(.data, org_id = NULL, paramRef = NULL,
dplyr::filter(organization_identifier %in% org_id)
}

# This updates the flagging column. Users who only creates an R dataframe in the R environment will need to
# This updates the flagging column. Users who only creates an R dataframe in the R environment will need to
# ensure they re-run the function with their completed paramRef as an input to reflect this column accurately.
Flag1 <- CreateParamUseRef %>%
dplyr::anti_join(
Expand Down Expand Up @@ -1431,18 +1432,18 @@ TADA_CreateUseParamRef <- function(.data, org_id = NULL, paramRef = NULL,
# set zoom size
set_zoom <- function(x) gsub('(?<=zoomScale=")[0-9]+', x, sV, perl = TRUE)
n_sheets <- length(wb$worksheets)
for(i in 1:n_sheets){
for (i in 1:n_sheets) {
sV <- wb$worksheets[[i]]$sheetViews
wb$worksheets[[i]]$sheetViews <- set_zoom(90)
}

# sV <- wb$worksheets[[2]]$sheetViews
# wb$worksheets[[2]]$sheetViews <- set_zoom(90)
# sV <- wb$worksheets[[3]]$sheetViews
# wb$worksheets[[3]]$sheetViews <- set_zoom(90)
# sV <- wb$worksheets[[4]]$sheetViews
# wb$worksheets[[4]]$sheetViews <- set_zoom(90)

# Format column header
header_st <- openxlsx::createStyle(textDecoration = "Bold")
# Format Column widths
Expand Down Expand Up @@ -1539,4 +1540,3 @@ TADA_CreateUseParamRef <- function(.data, org_id = NULL, paramRef = NULL,
}
return(CreateParamUseRef)
}

22 changes: 12 additions & 10 deletions R/CensoredDataSuite.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,23 @@ TADA_IDCensoredData <- function(.data) {
#' # and in instances where the measurement is non-detect, set the result value
#' # to half of the detection limit value. For over-detect measurements, retain
#' # the detection limit value as the result value as-is.
#' Data_Nutrients_UT_CensoredFlag <-
#' TADA_SimpleCensoredMethods(Data_Nutrients_UT, nd_method = "multiplier",
#' nd_multiplier = 0.5, od_method = "as-is", od_multiplier = "null")
#' Data_Nutrients_UT_CensoredFlag <-
#' TADA_SimpleCensoredMethods(Data_Nutrients_UT,
#' nd_method = "multiplier",
#' nd_multiplier = 0.5, od_method = "as-is", od_multiplier = "null"
#' )
#'
#' # Check for agreement between detection condition and detection limit type,
#' # Check for agreement between detection condition and detection limit type,
#' # and in instances where the measurement is non-detect, set the result value
#' # to a random value between 0 and the detection limit value. For over-detect
#' # measurements, retain the detection limit value as the result value as-is.
#' Data_Nutrients_UT_CensoredFlag <-
#' TADA_SimpleCensoredMethods(Data_Nutrients_UT,
#' nd_method = "randombelowlimit", nd_multiplier = "null",
#' od_method = "as-is", od_multiplier = "null")
#' Data_Nutrients_UT_CensoredFlag <-
#' TADA_SimpleCensoredMethods(Data_Nutrients_UT,
#' nd_method = "randombelowlimit", nd_multiplier = "null",
#' od_method = "as-is", od_multiplier = "null"
#' )
#' }
#'

#'
TADA_SimpleCensoredMethods <- function(.data, nd_method = "multiplier", nd_multiplier = 0.5, od_method = "as-is", od_multiplier = "null") {
# check .data has all of the required columns
expected_cols <- c(
Expand Down
10 changes: 5 additions & 5 deletions R/CriteriaComparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
#' Pair Results for Numeric Criteria Calculation (UNDER ACTIVE DEVELOPMENT)
#'
#' This function pairs TADA results with results from specified characteristics from the same
#' TADA.MonitoringLocation within a user-specified time window to facilitate the calculation of
#' numeric criteria. The columns created by TADA_AutoClean are required to run this function. If
#' TADA.MonitoringLocation within a user-specified time window to facilitate the calculation of
#' numeric criteria. The columns created by TADA_AutoClean are required to run this function. If
#' they are not present in the data frame, the function will stop and print an error message.
#'
#' Users can provide a pairing reference file (can be created using TADA_CreatePairRef) to specify
#' which combinations of TADA.CharacteristicName, TADA.ResultMeasure.MeasureUnit,
#' TADA.MethodSpeciationName, and TADA.ResultSampleFractionText should be used for hardness, pH,
#' temperature, salinity, chloride or other user-defined groups. If no ref is specified, all
#' temperature, salinity, chloride or other user-defined groups. If no ref is specified, all
#' possible combinations for hardness, pH, temperature, salinity and chloride will be used. It is
#' highly recommended that users perform all unit conversion and synonym harmonization before using
#' TADA_PairForCriteriaCalc.
Expand All @@ -204,7 +204,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
#' in the pairing ref.
#' @export
#'
#' @examples
#' @examples
#' \dontrun{
#' AL_df <- TADA_DataRetrieval(
#' startDate = "2010-11-30",
Expand All @@ -215,7 +215,7 @@ TADA_CreatePairRef <- function(.data, ph = TRUE, hardness = TRUE, temp = TRUE,
#'
#' AL_PairRef <- TADA_PairForCriteriaCalc(AL_df)
#' }
#'
#'
TADA_PairForCriteriaCalc <- function(.data, ref = "null", hours_range = 4) {
# check to see if user-supplied ref is a df
if (!is.character(ref)) {
Expand Down
36 changes: 19 additions & 17 deletions R/DataDiscoveryRetrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#' aoi_sf cannot be used with tribal_area_type. If countrycode, countycode, huc,
#' siteid, or statecode are used with aoi_sf or tribal_area_type they will be ignored
#' under the assumption that the sf object or tribal location are the intended
#' area of interest.
#'
#' area of interest.
#'
#' aoi_sf is only designed to work with polygon shapefiles.
#'
#' Users can reference the \href{https://www.epa.gov/waterdata/storage-and-retrieval-and-water-quality-exchange-domain-services-and-downloads}{WQX domain tables}
Expand All @@ -44,7 +44,7 @@
#' @param startDate Start Date string in the format YYYY-MM-DD, for example, "2020-01-01"
#' @param endDate End Date string in the format YYYY-MM-DD, for example, "2020-01-01"
#' @param aoi_sf An sf object to use for a query area of interest. If using a local shapefile,
#' sf::read_sf can be used to read in a user provided shapefile. This will only
#' sf::read_sf can be used to read in a user provided shapefile. This will only
#' work for polygons.
#' @param countrycode Code that identifies a country or ocean (e.g. countrycode = "CA" for Canada,
#' countrycode = "OA" for Atlantic Ocean).
Expand Down Expand Up @@ -1381,7 +1381,7 @@ make_groups <- function(x, maxrecs) {
#' @param time_col time column
#' @param tz_col time zone column
#' @param tz time zone
#'
#'
#' @examples
#' \dontrun{
#' # Find web service URLs for each Profile using WQP User Interface (https://www.waterqualitydata.us/)
Expand Down Expand Up @@ -1410,44 +1410,46 @@ make_groups <- function(x, maxrecs) {
#' tz_col = "ActivityStartTime.TimeZoneCode",
#' tz = "UTC"
#' )
#'
#'
#' # Re-run TADA_CheckRequiredFields, no longer returns error message
#' TADA_CheckRequiredFields(TADAProfile1)
#' }
#'
TADA_CreateDateTime <- function(.data, date_col, time_col, tz_col, tz){
#'
TADA_CreateDateTime <- function(.data, date_col, time_col, tz_col, tz) {
offsetLibrary <- data.frame(
offset = c(5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 10, 0, 0, 0, 0),
code = c("EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT",
"AKST", "AKDT", "HAST", "HST", "UTC", "", NA, "GMT")
code = c(
"EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT",
"AKST", "AKDT", "HAST", "HST", "UTC", "", NA, "GMT"
)
)

# Difference in behavior between NWIS and WQP
offsetLibrary$offset[is.na(offsetLibrary$code)] <- NA
original_order <- names(.data)

.data <- merge(
x = .data,
y = offsetLibrary,
by.x = tz_col,
by.y = "code",
all.x = TRUE
)

.data$dateTime <- paste(.data[[date_col]], .data[[time_col]])
.data$dateTime <- lubridate::fast_strptime(
.data$dateTime,
"%Y-%m-%d %H:%M:%S"
) + 60 * 60 * .data$offset

attr(.data$dateTime, "tzone") <- tz

.data[[date_col]] <- suppressWarnings(as.Date(lubridate::parse_date_time(.data[[date_col]], c("Ymd", "mdY"))))

.data <- .data[, c(original_order, "offset", "dateTime")]

names(.data)[names(.data) == "offset"] <- paste0(tz_col, "_offset")
names(.data)[names(.data) == "dateTime"] <- paste0(date_col, "Time")

return(.data)
}
6 changes: 3 additions & 3 deletions R/DepthProfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' TADA.MonitoringLocation, ActivityDate, Organization ID, and TADA.CharacteristicName combination.
#' When dailyagg == "min" or when dailyagg == "max", the min or max
#' value in each group of results (as determined by the depth category) will
#' be identified or calculated for each TADA.MonitoringLocation, ActivityDate, and
#' be identified or calculated for each TADA.MonitoringLocation, ActivityDate, and
#' TADA.CharacteristicName combination. An additional column, TADA.DepthProfileAggregation.Flag will
#' be added to describe aggregation.
#'
Expand Down Expand Up @@ -89,7 +89,7 @@
#' bycategory = "all", dailyagg = "avg", aggregatedonly = FALSE
#' )
#'
TADA_FlagDepthCategory <- function(.data, bycategory = "no", bottomvalue = 2, surfacevalue = 2,
TADA_FlagDepthCategory <- function(.data, bycategory = "no", bottomvalue = 2, surfacevalue = 2,
dailyagg = "none", aggregatedonly = FALSE, clean = FALSE) {
# check .data is data.frame
TADA_CheckType(.data, "data.frame", "Input object")
Expand Down Expand Up @@ -690,7 +690,7 @@ TADA_IDDepthProfiles <- function(.data, nresults = TRUE, nvalue = 2, aggregates
#' depthcat = FALSE
#' )
#' }
#'
#'
TADA_DepthProfilePlot <- function(.data,
groups = NULL,
location = NULL,
Expand Down
57 changes: 37 additions & 20 deletions R/Figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#' # Create multiple boxplots with additional grouping columns and view the first
#' # plot in list. In this example, we will group data in the input dataframe
#' # by both the TADA.ComparableDataIdentifier and the OrganizationIdentifier
#' Boxplots_TPbyOrg <- TADA_Boxplot(df, id_cols =
#' c("TADA.ComparableDataIdentifier", "OrganizationIdentifier"))
#' Boxplots_TPbyOrg <- TADA_Boxplot(df,
#' id_cols =
#' c("TADA.ComparableDataIdentifier", "OrganizationIdentifier")
#' )
#' # This example generates 2 box plots.
#' Boxplots_TPbyOrg[[1]]
#' Boxplots_TPbyOrg[[2]]
Expand All @@ -49,8 +51,9 @@
#' # (e.g. stream, reservoir, canal, etc.)
#' # Load example dataframe:
#' data(Data_Nutrients_UT)
#' Boxplot_output <- TADA_Boxplot(Data_Nutrients_UT,
#' id_cols = c("TADA.ComparableDataIdentifier", "MonitoringLocationTypeName"))
#' Boxplot_output <- TADA_Boxplot(Data_Nutrients_UT,
#' id_cols = c("TADA.ComparableDataIdentifier", "MonitoringLocationTypeName")
#' )
#' # This example generates 32 box plots.
#' Boxplot_output[[2]]
#' Boxplot_output[[25]]
Expand Down Expand Up @@ -229,9 +232,12 @@ TADA_Boxplot <- function(.data, id_cols = c("TADA.ComparableDataIdentifier")) {
#' # and MonitoringLocationTypeName (e.g. stream, reservoir, canal, etc.)
#' # Load example dataframe:
#' data(Data_Nutrients_UT)
#' Histogram_output <- TADA_Histogram(Data_Nutrients_UT,
#' id_cols = c("TADA.ComparableDataIdentifier",
#' "MonitoringLocationTypeName"))
#' Histogram_output <- TADA_Histogram(Data_Nutrients_UT,
#' id_cols = c(
#' "TADA.ComparableDataIdentifier",
#' "MonitoringLocationTypeName"
#' )
#' )
#' # This example generates 32 histograms
#' Histogram_output[[10]]
#' Histogram_output[[25]]
Expand Down Expand Up @@ -679,11 +685,13 @@ TADA_FlaggedSitesMap <- function(.data) {
#' # Create a list of parameters in the dataset and the number of records of
#' # each parameter:
#' TADA_FieldValuesPie(Data_Nutrients_UT, field = "TADA.CharacteristicName")
#' # If there are more than 12 categories to display, any remaining categories,
#' # If there are more than 12 categories to display, any remaining categories,
#' # the ones that have the smallest number of results,
#' # are combined into an "ALL OTHERS" category.
#' TADA_FieldValuesPie(Data_Nutrients_UT, field =
#' "TADA.ComparableDataIdentifier")
#' TADA_FieldValuesPie(Data_Nutrients_UT,
#' field =
#' "TADA.ComparableDataIdentifier"
#' )
#'
TADA_FieldValuesPie <- function(.data, field = "null", characteristicName = "null") {
dat <- utils::head(TADA_FieldValuesTable(.data = .data, field = field, characteristicName = characteristicName), 12)
Expand Down Expand Up @@ -1207,26 +1215,35 @@ TADA_TwoCharacteristicScatterplot <- function(.data, id_cols = "TADA.ComparableD
#' df2 <- TADA_SimpleCensoredMethods(Data_Nutrients_UT)
#' # create scatterplots for selected counties
#' UT_Nutrients_by_CountyCode <- TADA_GroupedScatterplot(
#' df2, group_col = "CountyCode", groups = c("057", "011", "003", "037"))
#' df2,
#' group_col = "CountyCode", groups = c("057", "011", "003", "037")
#' )
#' # view the 3rd and 4th plots
#' UT_Nutrients_by_CountyCode[[3]]
#' UT_Nutrients_by_CountyCode[[4]]
#'
#' # Load example dataset:
#' data(Data_6Tribes_5y_Harmonized)
#'
#' # Filter the example data so it includes only one
#' # Filter the example data so it includes only one
#' # TADA.ComparableDataIdentifier
#' df <- dplyr::filter(Data_6Tribes_5y_Harmonized,
#' TADA.ComparableDataIdentifier %in% c(
#' "TOTAL PHOSPHORUS, MIXED FORMS_UNFILTERED_AS P_UG/L"))
#' # Creates a scatterplot of the three specified sites of interest in the
#' df <- dplyr::filter(
#' Data_6Tribes_5y_Harmonized,
#' TADA.ComparableDataIdentifier %in% c(
#' "TOTAL PHOSPHORUS, MIXED FORMS_UNFILTERED_AS P_UG/L"
#' )
#' )
#' # Creates a scatterplot of the three specified sites of interest in the
#' # same plot.
#' TADA_GroupedScatterplot(df, group_col = "MonitoringLocationName",
#' groups = c("Upper Red Lake: West", "Upper Red Lake: West-Central",
#' "Upper Red Lake: East Central"))
#' TADA_GroupedScatterplot(df,
#' group_col = "MonitoringLocationName",
#' groups = c(
#' "Upper Red Lake: West", "Upper Red Lake: West-Central",
#' "Upper Red Lake: East Central"
#' )
#' )
#'
#' # If no groups are selected, return the 4 groups
#' # If no groups are selected, return the 4 groups
#' # (by MonitoringLocationName) with the greatest number of results
#' TADA_GroupedScatterplot(df, group_col = "MonitoringLocationName")
#'
Expand Down
Loading
Loading