From a6da94ceb41557a6cacdca7c8856608b31b2849f Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:44:33 -0500 Subject: [PATCH 01/10] update TADA_CheckRequiredFields return names of missing cols with error, update autoclean to add ActivityStartDateTime if missing --- R/RequiredCols.R | 22 ++++++++++++++-------- R/Utilities.R | 12 +++++++++++- man/TADA_CheckRequiredFields.Rd | 16 ++++++++++------ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/R/RequiredCols.R b/R/RequiredCols.R index e5b2eb5a..b815340e 100644 --- a/R/RequiredCols.R +++ b/R/RequiredCols.R @@ -341,14 +341,13 @@ TADA_GetTemplate <- function() { -#' TADA Module 1 Required Fields Check +#' TADA Required Fields Check #' -#' This function checks if all required fields for TADA Module 1 are -#' included in the input dataframe. +#' This function checks if all fields required to run TADA functions are included in the input dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility with the application. #' #' @param .data A dataframe #' -#' @return Boolean result indicating whether or not the input dataframe contains all of the TADA profile fields. +#' @return Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all of the required fields. If FALSE, an error will be returned that includes the names of all missing columns. #' #' @export #' @@ -365,8 +364,13 @@ TADA_GetTemplate <- function() { #' # Join all three profiles using TADA_JoinWQPProfiles #' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) #' -#' # Run TADA_CheckRequiredFields -#' CheckRequirements_TADAProfile <- TADA_CheckRequiredFields(TADAProfile) +#' # Run TADA_CheckRequiredFields, returns error message, 'The dataframe does not contain the required fields: ActivityStartDateTime' +#' TADA_CheckRequiredFields(TADAProfile) +#' +#' # Add missing col +#' TADAProfile$ActivityStartDateTime <- as.POSIXct(paste(TADAProfile$ActivityStartDate, TADAProfile$ActivityStartTime.Time), tz = "UTC") +#' # re-run check, returns 'TRUE' +#' TADA_CheckRequiredFields(TADAProfile) #' } #' TADA_CheckRequiredFields <- function(.data) { @@ -380,8 +384,10 @@ TADA_CheckRequiredFields <- function(.data) { if (all(require.originals %in% colnames(.data)) == TRUE) { TRUE } else { - stop("The dataframe does not contain the required fields.") - } + missingcols <- base::setdiff(require.originals, colnames(.data)) + stop("The dataframe does not contain the required fields: ", + paste(as.character(missingcols), + collapse = ", ")) } } diff --git a/R/Utilities.R b/R/Utilities.R index 5e54198e..8885adc4 100644 --- a/R/Utilities.R +++ b/R/Utilities.R @@ -224,7 +224,6 @@ TADA_AutoClean <- function(.data) { # execute function after checks are passed - # check to make sure columns do not already exist and capitalize fields with known synonyms that # only differ in caps print("TADA_Autoclean: creating TADA-specific columns.") @@ -272,6 +271,17 @@ TADA_AutoClean <- function(.data) { .data$TADA.ResultMeasure.MeasureUnitCode <- toupper(.data$ResultMeasure.MeasureUnitCode) } + if ("ActivityStartDateTime" %in% colnames(.data)) { + .data <- .data + } else { + # create ActivityStartDateTime from ActivityStartDate and ActivityStartTime.Time + # this is only needed when dataRetrieval is not used to get WQP data + # need to edit so the formats are the same -- data retrieval includes "2022-06-08 16:00:00" + # vs. this produces "2023-05-11 11:45:00 UTC" + .data$ActivityStartDateTime <- as.POSIXct( + paste(.data$ActivityStartDate, .data$ActivityStartTime.Time), tz = "UTC") + } + # Transform "Dissolved oxygen (DO)" characteristic name to "DISSOLVED OXYGEN SATURATION" IF # result unit is "%" or "% SATURATN". diff --git a/man/TADA_CheckRequiredFields.Rd b/man/TADA_CheckRequiredFields.Rd index ae2283a0..11b45d80 100644 --- a/man/TADA_CheckRequiredFields.Rd +++ b/man/TADA_CheckRequiredFields.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/RequiredCols.R \name{TADA_CheckRequiredFields} \alias{TADA_CheckRequiredFields} -\title{TADA Module 1 Required Fields Check} +\title{TADA Required Fields Check} \usage{ TADA_CheckRequiredFields(.data) } @@ -10,11 +10,10 @@ TADA_CheckRequiredFields(.data) \item{.data}{A dataframe} } \value{ -Boolean result indicating whether or not the input dataframe contains all of the TADA profile fields. +Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all of the required fields. If FALSE, an error will be returned that includes the names of all missing columns. } \description{ -This function checks if all required fields for TADA Module 1 are -included in the input dataframe. +This function checks if all fields required to run TADA functions are included in the input dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility with the application. } \examples{ \dontrun{ @@ -29,8 +28,13 @@ projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/ # Join all three profiles using TADA_JoinWQPProfiles TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) -# Run TADA_CheckRequiredFields -CheckRequirements_TADAProfile <- TADA_CheckRequiredFields(TADAProfile) +# Run TADA_CheckRequiredFields, returns error message, 'The dataframe does not contain the required fields: ActivityStartDateTime' +TADA_CheckRequiredFields(TADAProfile) + +# Add missing col +TADAProfile$ActivityStartDateTime <- as.POSIXct(paste(TADAProfile$ActivityStartDate, TADAProfile$ActivityStartTime.Time), tz = "UTC") +# re-run check, returns 'TRUE' +TADA_CheckRequiredFields(TADAProfile) } } From e86259e0cd60ac77edbc23c30baf060848e6a48a Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:23:23 -0500 Subject: [PATCH 02/10] use dataRetrieval:::create_dateTime to create ActivityStartDateTime in autoclean --- R/RequiredCols.R | 23 +++++++++++++++++------ R/Utilities.R | 11 ++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/R/RequiredCols.R b/R/RequiredCols.R index b815340e..3c4d017c 100644 --- a/R/RequiredCols.R +++ b/R/RequiredCols.R @@ -355,22 +355,33 @@ TADA_GetTemplate <- function() { #' \dontrun{ #' # Find web service URLs for each Profile using WQP User Interface (https://www.waterqualitydata.us/) #' # Example WQP URL: https://www.waterqualitydata.us/#statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&providers=NWIS&providers=STEWARDS&providers=STORET -#' +#' #' # Use TADA_ReadWQPWebServices to load the Station, Project, and Phys-Chem Result profiles #' stationProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Station/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") #' physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Result/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&dataProfile=resultPhysChem&providers=NWIS&providers=STEWARDS&providers=STORET") #' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") -#' +#' #' # Join all three profiles using TADA_JoinWQPProfiles #' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) -#' +#' #' # Run TADA_CheckRequiredFields, returns error message, 'The dataframe does not contain the required fields: ActivityStartDateTime' #' TADA_CheckRequiredFields(TADAProfile) #' #' # Add missing col -#' TADAProfile$ActivityStartDateTime <- as.POSIXct(paste(TADAProfile$ActivityStartDate, TADAProfile$ActivityStartTime.Time), tz = "UTC") -#' # re-run check, returns 'TRUE' -#' TADA_CheckRequiredFields(TADAProfile) +#' TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, +#' date_col = "ActivityStartDate", +#' time_col = "ActivityStartTime.Time", +#' tz_col = "ActivityStartTime.TimeZoneCode", +#' tz = "UTC") +#' +#' review_TADAProfile1 = TADAProfile1 %>% dplyr::select(c("ActivityStartDate", +#' "ActivityStartTime.Time", +#' "ActivityStartTime.TimeZoneCode", +#' "ActivityStartDateTime", +#' "ActivityStartTime.TimeZoneCode_offset")) +#' +#' # re-run TADA_CheckRequiredFields, returns TRUE +#' TADA_CheckRequiredFields(TADAProfile1) #' } #' TADA_CheckRequiredFields <- function(.data) { diff --git a/R/Utilities.R b/R/Utilities.R index 8885adc4..b1c0600a 100644 --- a/R/Utilities.R +++ b/R/Utilities.R @@ -274,12 +274,13 @@ TADA_AutoClean <- function(.data) { if ("ActivityStartDateTime" %in% colnames(.data)) { .data <- .data } else { - # create ActivityStartDateTime from ActivityStartDate and ActivityStartTime.Time + # creates ActivityStartDateTime and ActivityStartTime.TimeZoneCode_offset # this is only needed when dataRetrieval is not used to get WQP data - # need to edit so the formats are the same -- data retrieval includes "2022-06-08 16:00:00" - # vs. this produces "2023-05-11 11:45:00 UTC" - .data$ActivityStartDateTime <- as.POSIXct( - paste(.data$ActivityStartDate, .data$ActivityStartTime.Time), tz = "UTC") + .data <- dataRetrieval:::create_dateTime(df = .data, + date_col = "ActivityStartDate", + time_col = "ActivityStartTime.Time", + tz_col = "ActivityStartTime.TimeZoneCode", + tz = "UTC") } # Transform "Dissolved oxygen (DO)" characteristic name to "DISSOLVED OXYGEN SATURATION" IF From 16ee6692a14aa4aba96dd83ddcc8730d62303802 Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:23:38 -0500 Subject: [PATCH 03/10] Update TADA_CheckRequiredFields.Rd --- man/TADA_CheckRequiredFields.Rd | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/man/TADA_CheckRequiredFields.Rd b/man/TADA_CheckRequiredFields.Rd index 11b45d80..d9df582b 100644 --- a/man/TADA_CheckRequiredFields.Rd +++ b/man/TADA_CheckRequiredFields.Rd @@ -32,9 +32,20 @@ TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stat TADA_CheckRequiredFields(TADAProfile) # Add missing col -TADAProfile$ActivityStartDateTime <- as.POSIXct(paste(TADAProfile$ActivityStartDate, TADAProfile$ActivityStartTime.Time), tz = "UTC") -# re-run check, returns 'TRUE' -TADA_CheckRequiredFields(TADAProfile) +TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, + date_col = "ActivityStartDate", + time_col = "ActivityStartTime.Time", + tz_col = "ActivityStartTime.TimeZoneCode", + tz = "UTC") + +review_TADAProfile1 = TADAProfile1 \%>\% dplyr::select(c("ActivityStartDate", + "ActivityStartTime.Time", + "ActivityStartTime.TimeZoneCode", + "ActivityStartDateTime", + "ActivityStartTime.TimeZoneCode_offset")) + +# re-run TADA_CheckRequiredFields, returns TRUE +TADA_CheckRequiredFields(TADAProfile1) } } From 0c5ff57520a4ce407bbb0e8664c3539bbb4d0a3e Mon Sep 17 00:00:00 2001 From: hillarymarler Date: Tue, 17 Dec 2024 13:03:31 -0500 Subject: [PATCH 04/10] Update RequiredCols.R A few suggested formatting changes to get lines in documentation < 100 chars (for CRAN related checks). I did not attempt to shorten/format the URLs - those will still trigger that warning. --- R/RequiredCols.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R/RequiredCols.R b/R/RequiredCols.R index 3c4d017c..fff85565 100644 --- a/R/RequiredCols.R +++ b/R/RequiredCols.R @@ -343,11 +343,15 @@ TADA_GetTemplate <- function() { #' TADA Required Fields Check #' -#' This function checks if all fields required to run TADA functions are included in the input dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility with the application. +#' This function checks if all fields required to run TADA functions are included in the input +#' dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility +#' with the application. #' #' @param .data A dataframe #' -#' @return Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all of the required fields. If FALSE, an error will be returned that includes the names of all missing columns. +#' @return Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all +#' of the required fields. If FALSE, an error will be returned that includes the names of all +#' missing columns. #' #' @export #' @@ -362,9 +366,11 @@ TADA_GetTemplate <- function() { #' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") #' #' # Join all three profiles using TADA_JoinWQPProfiles -#' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) +#' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, +#' Projects = projectProfile) #' -#' # Run TADA_CheckRequiredFields, returns error message, 'The dataframe does not contain the required fields: ActivityStartDateTime' +#' # Run TADA_CheckRequiredFields, returns error message, +#' # 'The dataframe does not contain the required fields: ActivityStartDateTime' #' TADA_CheckRequiredFields(TADAProfile) #' #' # Add missing col From 883f23afe5ae0d9d30bd06501f9c6c1e158bb08f Mon Sep 17 00:00:00 2001 From: hillarymarler Date: Tue, 17 Dec 2024 13:51:59 -0500 Subject: [PATCH 05/10] Update Utilities.R Now TADA_RandomTestingData will re-run until it returns at least 10 results --- R/Utilities.R | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/R/Utilities.R b/R/Utilities.R index 5e54198e..8e447be6 100644 --- a/R/Utilities.R +++ b/R/Utilities.R @@ -915,7 +915,9 @@ TADA_GetUniqueNearbySites <- function(.data) { #' #' Retrieves data for a period of time in the past 20 years using #' TADA_DataRetrieval. This function can be used for testing functions on -#' random datasets. +#' random datasets. Only random data sets with 10 or more results will be returned. +#' If a random dataset has fewer than 10 results, the function will automatically +#' create another random WQP query until a df with greater than 10 results is returned. #' #' @param number_of_days Numeric. The default is 1, which will query and retrieve #' data for a random two-day period (e.g.startDate = "2015-04-21", @@ -944,19 +946,20 @@ TADA_GetUniqueNearbySites <- function(.data) { #' } #' TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FALSE, autoclean = TRUE) { - while (TRUE) { + + get_random_data <- function(ndays = number_of_days, state_choice = choose_random_state, ac = autoclean) { # choose a random day within the last 20 years twenty_yrs_ago <- Sys.Date() - 20 * 365 random_start_date <- twenty_yrs_ago + sample(20 * 365, 1) # choose a random start date and add any number_of_days (set that as the end date) - end_date <- random_start_date + number_of_days + end_date <- random_start_date + ndays - if (choose_random_state == TRUE) { + if (state_choice == TRUE) { load(system.file("extdata", "statecodes_df.Rdata", package = "EPATADA")) state <- sample(statecodes_df$STUSAB, 1) } - if (choose_random_state == FALSE) { + if (state_choice == FALSE) { state <- "null" } @@ -966,7 +969,7 @@ TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FAL statecode = state )) - if (autoclean == TRUE) { + if (ac == TRUE) { dat <- TADA_DataRetrieval( startDate = as.character(random_start_date), endDate = as.character(end_date), @@ -975,7 +978,7 @@ TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FAL ) } - if (autoclean == FALSE) { + if (ac == FALSE) { dat <- TADA_DataRetrieval( startDate = as.character(random_start_date), endDate = as.character(end_date), @@ -983,11 +986,18 @@ TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FAL applyautoclean = FALSE ) } - - if (nrow(dat) > 0) { - return(dat) + return(dat) + } + + verify_random_data <- function() { + df <- get_random_data() + while(nrow(df) < 10) { + df <- get_random_data() } + return(df) } + + verify_random_data() } #' Aggregate multiple result values to a min, max, or mean From 2494bbdf4297877cbca10f41f42e9c883ed9f732 Mon Sep 17 00:00:00 2001 From: hillarymarler Date: Tue, 17 Dec 2024 13:56:14 -0500 Subject: [PATCH 06/10] Update Utilities.R --- R/Utilities.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/Utilities.R b/R/Utilities.R index 8e447be6..7fed1583 100644 --- a/R/Utilities.R +++ b/R/Utilities.R @@ -945,9 +945,11 @@ TADA_GetUniqueNearbySites <- function(.data) { #' df <- TADA_RandomTestingData(number_of_days = 5, choose_random_state = TRUE, autoclean = FALSE) #' } #' -TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FALSE, autoclean = TRUE) { +TADA_RandomTestingData <- function(number_of_days = 1, choose_random_state = FALSE, + autoclean = TRUE) { - get_random_data <- function(ndays = number_of_days, state_choice = choose_random_state, ac = autoclean) { + get_random_data <- function(ndays = number_of_days, state_choice = choose_random_state, + ac = autoclean) { # choose a random day within the last 20 years twenty_yrs_ago <- Sys.Date() - 20 * 365 random_start_date <- twenty_yrs_ago + sample(20 * 365, 1) From 788045467571956f23a6bc27d8eb71bf82121689 Mon Sep 17 00:00:00 2001 From: hillarymarler Date: Tue, 17 Dec 2024 13:56:47 -0500 Subject: [PATCH 07/10] Update TADA_RandomTestingData.Rd --- man/TADA_RandomTestingData.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/TADA_RandomTestingData.Rd b/man/TADA_RandomTestingData.Rd index 7a20560e..7634dc26 100644 --- a/man/TADA_RandomTestingData.Rd +++ b/man/TADA_RandomTestingData.Rd @@ -32,7 +32,9 @@ Random WQP dataset. \description{ Retrieves data for a period of time in the past 20 years using TADA_DataRetrieval. This function can be used for testing functions on -random datasets. +random datasets. Only random data sets with 10 or more results will be returned. +If a random dataset has fewer than 10 results, the function will automatically +create another random WQP query until a df with greater than 10 results is returned. } \examples{ \dontrun{ From 878d562db2acae83d5b5ef01db98e49450287431 Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:58:18 -0500 Subject: [PATCH 08/10] update error message to include function name --- R/RequiredCols.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/RequiredCols.R b/R/RequiredCols.R index fff85565..0477bd04 100644 --- a/R/RequiredCols.R +++ b/R/RequiredCols.R @@ -402,7 +402,7 @@ TADA_CheckRequiredFields <- function(.data) { TRUE } else { missingcols <- base::setdiff(require.originals, colnames(.data)) - stop("The dataframe does not contain the required fields: ", + stop("TADA_CheckRequiredFields: the dataframe does not contain the required fields: ", paste(as.character(missingcols), collapse = ", ")) } } From 0a270602b1bdb061d05907ba097c830acfb754dd Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:58:28 -0500 Subject: [PATCH 09/10] Update TADA_CheckRequiredFields.Rd --- man/TADA_CheckRequiredFields.Rd | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/man/TADA_CheckRequiredFields.Rd b/man/TADA_CheckRequiredFields.Rd index d9df582b..9cc9210f 100644 --- a/man/TADA_CheckRequiredFields.Rd +++ b/man/TADA_CheckRequiredFields.Rd @@ -10,10 +10,14 @@ TADA_CheckRequiredFields(.data) \item{.data}{A dataframe} } \value{ -Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all of the required fields. If FALSE, an error will be returned that includes the names of all missing columns. +Boolean result, TRUE or FALSE, indicating whether or not the input dataframe contains all +of the required fields. If FALSE, an error will be returned that includes the names of all +missing columns. } \description{ -This function checks if all fields required to run TADA functions are included in the input dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility with the application. +This function checks if all fields required to run TADA functions are included in the input +dataframe. It is used in the TADA Shiny application to test user supplied files for compatibility +with the application. } \examples{ \dontrun{ @@ -26,9 +30,11 @@ physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US\%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") # Join all three profiles using TADA_JoinWQPProfiles -TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) +TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, + Projects = projectProfile) -# Run TADA_CheckRequiredFields, returns error message, 'The dataframe does not contain the required fields: ActivityStartDateTime' +# Run TADA_CheckRequiredFields, returns error message, +# 'The dataframe does not contain the required fields: ActivityStartDateTime' TADA_CheckRequiredFields(TADAProfile) # Add missing col From f776a29f892499e3374901ee42710d8a5039e282 Mon Sep 17 00:00:00 2001 From: cristinamullin <46969696+cristinamullin@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:09:51 -0500 Subject: [PATCH 10/10] update docs --- R/RequiredCols.R | 18 +++++++++--------- man/TADA_CheckRequiredFields.Rd | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/R/RequiredCols.R b/R/RequiredCols.R index 0477bd04..80c4482a 100644 --- a/R/RequiredCols.R +++ b/R/RequiredCols.R @@ -366,30 +366,30 @@ TADA_GetTemplate <- function() { #' projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") #' #' # Join all three profiles using TADA_JoinWQPProfiles -#' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, +#' TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, #' Projects = projectProfile) #' -#' # Run TADA_CheckRequiredFields, returns error message, +#' # Run TADA_CheckRequiredFields, returns error message, #' # 'The dataframe does not contain the required fields: ActivityStartDateTime' #' TADA_CheckRequiredFields(TADAProfile) #' #' # Add missing col -#' TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, -#' date_col = "ActivityStartDate", +#' TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, +#' date_col = "ActivityStartDate", #' time_col = "ActivityStartTime.Time", -#' tz_col = "ActivityStartTime.TimeZoneCode", +#' tz_col = "ActivityStartTime.TimeZoneCode", #' tz = "UTC") #' -#' review_TADAProfile1 = TADAProfile1 %>% dplyr::select(c("ActivityStartDate", -#' "ActivityStartTime.Time", -#' "ActivityStartTime.TimeZoneCode", +#' review_TADAProfile1 = TADAProfile1 %>% dplyr::select(c("ActivityStartDate", +#' "ActivityStartTime.Time", +#' "ActivityStartTime.TimeZoneCode", #' "ActivityStartDateTime", #' "ActivityStartTime.TimeZoneCode_offset")) #' #' # re-run TADA_CheckRequiredFields, returns TRUE #' TADA_CheckRequiredFields(TADAProfile1) #' } -#' +#' TADA_CheckRequiredFields <- function(.data) { # remove names with TADA. string from require.cols require.originals <- Filter(function(x) !any(grepl("TADA.", x)), require.cols) diff --git a/man/TADA_CheckRequiredFields.Rd b/man/TADA_CheckRequiredFields.Rd index 9cc9210f..08a08748 100644 --- a/man/TADA_CheckRequiredFields.Rd +++ b/man/TADA_CheckRequiredFields.Rd @@ -30,23 +30,23 @@ physchemProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data projectProfile <- TADA_ReadWQPWebServices("https://www.waterqualitydata.us/data/Project/search?statecode=US\%3A09&characteristicType=Nutrient&startDateLo=04-01-2023&startDateHi=11-01-2023&mimeType=csv&zip=yes&providers=NWIS&providers=STEWARDS&providers=STORET") # Join all three profiles using TADA_JoinWQPProfiles -TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, +TADAProfile <- TADA_JoinWQPProfiles(FullPhysChem = physchemProfile, Sites = stationProfile, Projects = projectProfile) -# Run TADA_CheckRequiredFields, returns error message, +# Run TADA_CheckRequiredFields, returns error message, # 'The dataframe does not contain the required fields: ActivityStartDateTime' TADA_CheckRequiredFields(TADAProfile) # Add missing col -TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, - date_col = "ActivityStartDate", +TADAProfile1 <- dataRetrieval:::create_dateTime(df = TADAProfile, + date_col = "ActivityStartDate", time_col = "ActivityStartTime.Time", - tz_col = "ActivityStartTime.TimeZoneCode", + tz_col = "ActivityStartTime.TimeZoneCode", tz = "UTC") -review_TADAProfile1 = TADAProfile1 \%>\% dplyr::select(c("ActivityStartDate", - "ActivityStartTime.Time", - "ActivityStartTime.TimeZoneCode", +review_TADAProfile1 = TADAProfile1 \%>\% dplyr::select(c("ActivityStartDate", + "ActivityStartTime.Time", + "ActivityStartTime.TimeZoneCode", "ActivityStartDateTime", "ActivityStartTime.TimeZoneCode_offset"))