From ab16004b6a4d65b228030d7439e4304471b05966 Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Tue, 19 Mar 2024 16:11:36 -0700 Subject: [PATCH 01/27] add being able to load data from AGOL --- R/utils.R | 138 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 66 deletions(-) diff --git a/R/utils.R b/R/utils.R index b8a92fc..e86d091 100644 --- a/R/utils.R +++ b/R/utils.R @@ -78,71 +78,71 @@ GetColSpec <- function() { DataStoreReferenceCode = readr::col_integer(), .default = readr::col_character() ), - BMI = readr::cols( - VisitDate = readr::col_date(), - DateCollected = readr::col_date(), - FieldSplit = readr::col_integer(), - LabSplit = readr::col_double(), - SampleArea_m2 = readr::col_double(), - Abundance = readr::col_integer(), - Richness = readr::col_integer(), - DominantTaxaPercent = readr::col_double(), - SplitCount = readr::col_integer(), - FixedCount = readr::col_integer(), - BigRareCount = readr::col_integer(), - ShannonsDiversity = readr::col_double(), - SimpsonsDiversity = readr::col_double(), - Evenness = readr::col_double(), - EPTTaxaCount = readr::col_integer(), - EPTTaxaAbundance = readr::col_integer(), - DominantFamilyAbundance = readr::col_integer(), - DominantTaxaAbundance = readr::col_integer(), - Hilsenhoff = readr::col_double(), - IntolerantTaxaCount = readr::col_integer(), - IntolerantTaxaAbundance = readr::col_integer(), - TolerantTaxaCount = readr::col_integer(), - TolerantTaxaAbundance = readr::col_integer(), - USFSCommunityToleranceQuo = readr::col_integer(), - ShredderTaxaCount = readr::col_integer(), - ShredderAbundance = readr::col_integer(), - ScraperTaxaCount = readr::col_integer(), - ScraperAbundance = readr::col_integer(), - CollectorFiltererCount = readr::col_integer(), - CollectorFiltererAbundance = readr::col_integer(), - CollectorGathererCount = readr::col_integer(), - CollectorGathererAbundance = readr::col_integer(), - PredatorTaxaCount = readr::col_integer(), - PredatorTaxaAbundance = readr::col_integer(), - ClingerTaxaCount = readr::col_integer(), - LongLivedTaxa = readr::col_integer(), - EphemeropteraTaxaCount = readr::col_integer(), - EphemeropteraTaxaAbundance = readr::col_integer(), - PlecopteraTaxa = readr::col_integer(), - PlecopteraTaxaAbundance = readr::col_integer(), - TrichopteraTaxaCount = readr::col_integer(), - TrichopteraAbundance = readr::col_integer(), - ColeopteraTaxaCount = readr::col_integer(), - ColeopteraAbundance = readr::col_integer(), - ElmidaeTaxaCount = readr::col_integer(), - ElmidaeAbundance = readr::col_integer(), - MegalopteraTaxaCount = readr::col_integer(), - MegalopteraAbundance = readr::col_integer(), - DipteraTaxaCount = readr::col_integer(), - DipteraAbundance = readr::col_integer(), - ChironomidaeTaxaCount = readr::col_integer(), - ChironomidaeAbundance = readr::col_integer(), - CrustaceaTaxaCount = readr::col_integer(), - CrustaceaAbundance = readr::col_integer(), - OligochaeteTaxaCount = readr::col_integer(), - OligochaeteAbundance = readr::col_integer(), - MolluscaTaxaCount = readr::col_integer(), - MolluscaAbundance = readr::col_integer(), - InsectTaxaCount = readr::col_integer(), - InsectAbundance = readr::col_integer(), - NonInsectTaxaCount = readr::col_integer(), - NonInsectAbundance = readr::col_integer(), - .default = readr::col_character() - ), + # BMI = readr::cols( + # VisitDate = readr::col_date(), + # DateCollected = readr::col_date(), + # FieldSplit = readr::col_integer(), + # LabSplit = readr::col_double(), + # SampleArea_m2 = readr::col_double(), + # Abundance = readr::col_integer(), + # Richness = readr::col_integer(), + # DominantTaxaPercent = readr::col_double(), + # SplitCount = readr::col_integer(), + # FixedCount = readr::col_integer(), + # BigRareCount = readr::col_integer(), + # ShannonsDiversity = readr::col_double(), + # SimpsonsDiversity = readr::col_double(), + # Evenness = readr::col_double(), + # EPTTaxaCount = readr::col_integer(), + # EPTTaxaAbundance = readr::col_integer(), + # DominantFamilyAbundance = readr::col_integer(), + # DominantTaxaAbundance = readr::col_integer(), + # Hilsenhoff = readr::col_double(), + # IntolerantTaxaCount = readr::col_integer(), + # IntolerantTaxaAbundance = readr::col_integer(), + # TolerantTaxaCount = readr::col_integer(), + # TolerantTaxaAbundance = readr::col_integer(), + # USFSCommunityToleranceQuo = readr::col_integer(), + # ShredderTaxaCount = readr::col_integer(), + # ShredderAbundance = readr::col_integer(), + # ScraperTaxaCount = readr::col_integer(), + # ScraperAbundance = readr::col_integer(), + # CollectorFiltererCount = readr::col_integer(), + # CollectorFiltererAbundance = readr::col_integer(), + # CollectorGathererCount = readr::col_integer(), + # CollectorGathererAbundance = readr::col_integer(), + # PredatorTaxaCount = readr::col_integer(), + # PredatorTaxaAbundance = readr::col_integer(), + # ClingerTaxaCount = readr::col_integer(), + # LongLivedTaxa = readr::col_integer(), + # EphemeropteraTaxaCount = readr::col_integer(), + # EphemeropteraTaxaAbundance = readr::col_integer(), + # PlecopteraTaxa = readr::col_integer(), + # PlecopteraTaxaAbundance = readr::col_integer(), + # TrichopteraTaxaCount = readr::col_integer(), + # TrichopteraAbundance = readr::col_integer(), + # ColeopteraTaxaCount = readr::col_integer(), + # ColeopteraAbundance = readr::col_integer(), + # ElmidaeTaxaCount = readr::col_integer(), + # ElmidaeAbundance = readr::col_integer(), + # MegalopteraTaxaCount = readr::col_integer(), + # MegalopteraAbundance = readr::col_integer(), + # DipteraTaxaCount = readr::col_integer(), + # DipteraAbundance = readr::col_integer(), + # ChironomidaeTaxaCount = readr::col_integer(), + # ChironomidaeAbundance = readr::col_integer(), + # CrustaceaTaxaCount = readr::col_integer(), + # CrustaceaAbundance = readr::col_integer(), + # OligochaeteTaxaCount = readr::col_integer(), + # OligochaeteAbundance = readr::col_integer(), + # MolluscaTaxaCount = readr::col_integer(), + # MolluscaAbundance = readr::col_integer(), + # InsectTaxaCount = readr::col_integer(), + # InsectAbundance = readr::col_integer(), + # NonInsectTaxaCount = readr::col_integer(), + # NonInsectAbundance = readr::col_integer(), + # .default = readr::col_character() + # ), Channel = readr::cols( VisitDate = readr::col_date(), .default = readr::col_character() @@ -462,7 +462,8 @@ ReadAquariusLakes <- function(conn, data.name) { ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name) { col.spec <- GetColSpec() col.spec.aq <- GetAquariusColSpec() - col.spec.all <- c(col.spec, col.spec.aq) + col.spec.agol <- list("BMI") + col.spec.all <- c(col.spec, col.spec.aq, col.spec.agol) if (!(data.source %in% c("database", "local"))) { stop("Please choose either 'database' or 'local' for data.source") @@ -477,6 +478,11 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } else if (data.source == "database" & data.name %in% names(col.spec.aq)) { ## Read Aquarius data filtered.data <- ReadAquarius(conn, data.name) + } else if (data.source == "database" & data.name %in% names(col.spec.agol)) { + # TODO: create list/dictionary that can hold multiple URLS for different agol databases + filtered.data <- fetchagol::fetchRawData("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", "mojn_data") + filtered.data <- fetchagol::cleanData(filtered.data) + filtered.data <- filtered.data$data } else if (data.source == "local") { filtered.data <- readr::read_csv(file.path(path.to.data, paste0(data.name, ".csv")), na = "", col_types = col.spec.all[[data.name]], lazy = FALSE) if(data.name %in% names(col.spec.aq) & "DateTime" %in% names(filtered.data)) { From d90c9cbebd50ea0d04d47393549f2613bf8ee718 Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Tue, 19 Mar 2024 16:59:58 -0700 Subject: [PATCH 02/27] add dict for agol database urls --- R/utils.R | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/R/utils.R b/R/utils.R index e86d091..a11b103 100644 --- a/R/utils.R +++ b/R/utils.R @@ -459,10 +459,11 @@ ReadAquariusLakes <- function(conn, data.name) { #' #' @details \code{data.name} options are: Site, Visit, BMI, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature #' -ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name) { +ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name, + agol_url_dict = hash::hash(keys = c("BMI"), values = c("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer"))) { col.spec <- GetColSpec() col.spec.aq <- GetAquariusColSpec() - col.spec.agol <- list("BMI") + col.spec.agol <- c("BMI") col.spec.all <- c(col.spec, col.spec.aq, col.spec.agol) if (!(data.source %in% c("database", "local"))) { @@ -478,9 +479,9 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } else if (data.source == "database" & data.name %in% names(col.spec.aq)) { ## Read Aquarius data filtered.data <- ReadAquarius(conn, data.name) - } else if (data.source == "database" & data.name %in% names(col.spec.agol)) { + } else if (data.source == "database" & data.name %in% col.spec.agol) { # TODO: create list/dictionary that can hold multiple URLS for different agol databases - filtered.data <- fetchagol::fetchRawData("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", "mojn_data") + filtered.data <- fetchagol::fetchRawData(agol_url_dict[[data.name]], "mojn_data") filtered.data <- fetchagol::cleanData(filtered.data) filtered.data <- filtered.data$data } else if (data.source == "local") { @@ -490,32 +491,36 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } } - if (!missing(park)) { - filtered.data %<>% - dplyr::filter(Park == park) - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for the park specified")) + if (data.name %in% col.spec.agol) { + + } else{ + if (!missing(park)) { + filtered.data %<>% + dplyr::filter(Park == park) + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for the park specified")) + } } - } - if (!missing(site) & nrow(filtered.data) > 0) { - filtered.data %<>% - dplyr::filter(SiteCode %in% site) + if (!missing(site) & nrow(filtered.data) > 0) { + filtered.data %<>% + dplyr::filter(SiteCode %in% site) - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for the site specified")) + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for the site specified")) + } } - } - if ("FieldSeason" %in% names(filtered.data)) { - filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) - } + if ("FieldSeason" %in% names(filtered.data)) { + filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) + } - if (!missing(field.season) & ("FieldSeason" %in% colnames(filtered.data)) & nrow(filtered.data) > 0) { - filtered.data %<>% - dplyr::filter(FieldSeason %in% field.season) - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for one or more of the field seasons specified")) + if (!missing(field.season) & ("FieldSeason" %in% colnames(filtered.data)) & nrow(filtered.data) > 0) { + filtered.data %<>% + dplyr::filter(FieldSeason %in% field.season) + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for one or more of the field seasons specified")) + } } } From 3072477a24dc5f5c0c29cae0f450edc0df0a2afc Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Tue, 19 Mar 2024 17:27:24 -0700 Subject: [PATCH 03/27] add filtering for data pulled from agol --- R/utils.R | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/R/utils.R b/R/utils.R index a11b103..654a98f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -491,8 +491,53 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } } + # Filtering for data from AGOL if (data.name %in% col.spec.agol) { + if (!missing(park)) { + + filtered.data <- lapply(filtered.data, function(table){ + # If the table has a Park column filter for specified park + if("Park" %in% colnames(table)) { + table <- table %>% dplyr::filter(Park == park) + } + if (nrow(table) == 0) { + warning(paste0(data.name, ": Data are not available for the park specified")) + } + return(table) + })} + if (!missing(site) & length(filtered.data) > 0) { + # If the table has a SiteCode column filter for specified site + filtered.data <- lapply(filtered.data, function(table){ + if("SiteCode" %in% colnames(table)) { + table <- table %>% dplyr::filter(SiteCode %in% site) + + } + if (nrow(table) == 0) { + warning(paste0(data.name, ": Data are not available for the site specified")) + } + return(table) + })} + + # TODO: I dont think this is necessary for the AGOL data + # if ("FieldSeason" %in% names(filtered.data)) { + # filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) + # } + + if (!missing(field.season) & length(filtered.data) > 0) { + + # If the table has a SiteCode column filter for specified site + filtered.data <- lapply(filtered.data, function(table){ + if("FieldSeason" %in% colnames(table)) { + table <- table %>% dplyr::filter(FieldSeason %in% field.season) + + } + if (nrow(table) == 0) { + warning(paste0(data.name, ": Data are not available for the field season specified")) + } + return(table) + })} + # Filtering for any other data source besides AGOL } else{ if (!missing(park)) { filtered.data %<>% From ad8cc5f1f9fa1694661314e1464d9962cd39291b Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Thu, 21 Mar 2024 11:05:45 -0700 Subject: [PATCH 04/27] adding new bmi functions --- R/utils.R | 241 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 170 insertions(+), 71 deletions(-) diff --git a/R/utils.R b/R/utils.R index 654a98f..2ee9f0d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -78,71 +78,71 @@ GetColSpec <- function() { DataStoreReferenceCode = readr::col_integer(), .default = readr::col_character() ), - # BMI = readr::cols( - # VisitDate = readr::col_date(), - # DateCollected = readr::col_date(), - # FieldSplit = readr::col_integer(), - # LabSplit = readr::col_double(), - # SampleArea_m2 = readr::col_double(), - # Abundance = readr::col_integer(), - # Richness = readr::col_integer(), - # DominantTaxaPercent = readr::col_double(), - # SplitCount = readr::col_integer(), - # FixedCount = readr::col_integer(), - # BigRareCount = readr::col_integer(), - # ShannonsDiversity = readr::col_double(), - # SimpsonsDiversity = readr::col_double(), - # Evenness = readr::col_double(), - # EPTTaxaCount = readr::col_integer(), - # EPTTaxaAbundance = readr::col_integer(), - # DominantFamilyAbundance = readr::col_integer(), - # DominantTaxaAbundance = readr::col_integer(), - # Hilsenhoff = readr::col_double(), - # IntolerantTaxaCount = readr::col_integer(), - # IntolerantTaxaAbundance = readr::col_integer(), - # TolerantTaxaCount = readr::col_integer(), - # TolerantTaxaAbundance = readr::col_integer(), - # USFSCommunityToleranceQuo = readr::col_integer(), - # ShredderTaxaCount = readr::col_integer(), - # ShredderAbundance = readr::col_integer(), - # ScraperTaxaCount = readr::col_integer(), - # ScraperAbundance = readr::col_integer(), - # CollectorFiltererCount = readr::col_integer(), - # CollectorFiltererAbundance = readr::col_integer(), - # CollectorGathererCount = readr::col_integer(), - # CollectorGathererAbundance = readr::col_integer(), - # PredatorTaxaCount = readr::col_integer(), - # PredatorTaxaAbundance = readr::col_integer(), - # ClingerTaxaCount = readr::col_integer(), - # LongLivedTaxa = readr::col_integer(), - # EphemeropteraTaxaCount = readr::col_integer(), - # EphemeropteraTaxaAbundance = readr::col_integer(), - # PlecopteraTaxa = readr::col_integer(), - # PlecopteraTaxaAbundance = readr::col_integer(), - # TrichopteraTaxaCount = readr::col_integer(), - # TrichopteraAbundance = readr::col_integer(), - # ColeopteraTaxaCount = readr::col_integer(), - # ColeopteraAbundance = readr::col_integer(), - # ElmidaeTaxaCount = readr::col_integer(), - # ElmidaeAbundance = readr::col_integer(), - # MegalopteraTaxaCount = readr::col_integer(), - # MegalopteraAbundance = readr::col_integer(), - # DipteraTaxaCount = readr::col_integer(), - # DipteraAbundance = readr::col_integer(), - # ChironomidaeTaxaCount = readr::col_integer(), - # ChironomidaeAbundance = readr::col_integer(), - # CrustaceaTaxaCount = readr::col_integer(), - # CrustaceaAbundance = readr::col_integer(), - # OligochaeteTaxaCount = readr::col_integer(), - # OligochaeteAbundance = readr::col_integer(), - # MolluscaTaxaCount = readr::col_integer(), - # MolluscaAbundance = readr::col_integer(), - # InsectTaxaCount = readr::col_integer(), - # InsectAbundance = readr::col_integer(), - # NonInsectTaxaCount = readr::col_integer(), - # NonInsectAbundance = readr::col_integer(), - # .default = readr::col_character() - # ), + BMI = readr::cols( + VisitDate = readr::col_date(), + DateCollected = readr::col_date(), + FieldSplit = readr::col_integer(), + LabSplit = readr::col_double(), + SampleArea_m2 = readr::col_double(), + Abundance = readr::col_integer(), + Richness = readr::col_integer(), + DominantTaxaPercent = readr::col_double(), + SplitCount = readr::col_integer(), + FixedCount = readr::col_integer(), + BigRareCount = readr::col_integer(), + ShannonsDiversity = readr::col_double(), + SimpsonsDiversity = readr::col_double(), + Evenness = readr::col_double(), + EPTTaxaCount = readr::col_integer(), + EPTTaxaAbundance = readr::col_integer(), + DominantFamilyAbundance = readr::col_integer(), + DominantTaxaAbundance = readr::col_integer(), + Hilsenhoff = readr::col_double(), + IntolerantTaxaCount = readr::col_integer(), + IntolerantTaxaAbundance = readr::col_integer(), + TolerantTaxaCount = readr::col_integer(), + TolerantTaxaAbundance = readr::col_integer(), + USFSCommunityToleranceQuo = readr::col_integer(), + ShredderTaxaCount = readr::col_integer(), + ShredderAbundance = readr::col_integer(), + ScraperTaxaCount = readr::col_integer(), + ScraperAbundance = readr::col_integer(), + CollectorFiltererCount = readr::col_integer(), + CollectorFiltererAbundance = readr::col_integer(), + CollectorGathererCount = readr::col_integer(), + CollectorGathererAbundance = readr::col_integer(), + PredatorTaxaCount = readr::col_integer(), + PredatorTaxaAbundance = readr::col_integer(), + ClingerTaxaCount = readr::col_integer(), + LongLivedTaxa = readr::col_integer(), + EphemeropteraTaxaCount = readr::col_integer(), + EphemeropteraTaxaAbundance = readr::col_integer(), + PlecopteraTaxa = readr::col_integer(), + PlecopteraTaxaAbundance = readr::col_integer(), + TrichopteraTaxaCount = readr::col_integer(), + TrichopteraAbundance = readr::col_integer(), + ColeopteraTaxaCount = readr::col_integer(), + ColeopteraAbundance = readr::col_integer(), + ElmidaeTaxaCount = readr::col_integer(), + ElmidaeAbundance = readr::col_integer(), + MegalopteraTaxaCount = readr::col_integer(), + MegalopteraAbundance = readr::col_integer(), + DipteraTaxaCount = readr::col_integer(), + DipteraAbundance = readr::col_integer(), + ChironomidaeTaxaCount = readr::col_integer(), + ChironomidaeAbundance = readr::col_integer(), + CrustaceaTaxaCount = readr::col_integer(), + CrustaceaAbundance = readr::col_integer(), + OligochaeteTaxaCount = readr::col_integer(), + OligochaeteAbundance = readr::col_integer(), + MolluscaTaxaCount = readr::col_integer(), + MolluscaAbundance = readr::col_integer(), + InsectTaxaCount = readr::col_integer(), + InsectAbundance = readr::col_integer(), + NonInsectTaxaCount = readr::col_integer(), + NonInsectAbundance = readr::col_integer(), + .default = readr::col_character() + ), Channel = readr::cols( VisitDate = readr::col_date(), .default = readr::col_character() @@ -256,6 +256,17 @@ GetAquariusColSpec <- function() { return(col.spec.aq) } +#' Get AGOL databases and their URLs +#' +#' @param agol_url_dict A dictionary of database names and URLs +#' +#' @returns A dict where keys are databases in AGOL and the values are the associated database URLs +#' +#' TODO add info about columns?? +GetAGOLInfo <- function(agol_url_dict = hash::hash(keys = c("BMI"), values = c("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer"))) { + return(agol_url_dict) +} + #' Read Streams and Lakes data from Aquarius #' #' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. @@ -459,11 +470,12 @@ ReadAquariusLakes <- function(conn, data.name) { #' #' @details \code{data.name} options are: Site, Visit, BMI, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature #' -ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name, - agol_url_dict = hash::hash(keys = c("BMI"), values = c("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer"))) { +ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name) { col.spec <- GetColSpec() col.spec.aq <- GetAquariusColSpec() - col.spec.agol <- c("BMI") + col.spec.agol <- hash::keys(GetAGOLInfo()) + #col.spec.agol <- c("BMI") + # TODO add agol stuff to this list correctly col.spec.all <- c(col.spec, col.spec.aq, col.spec.agol) if (!(data.source %in% c("database", "local"))) { @@ -480,8 +492,8 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data ## Read Aquarius data filtered.data <- ReadAquarius(conn, data.name) } else if (data.source == "database" & data.name %in% col.spec.agol) { - # TODO: create list/dictionary that can hold multiple URLS for different agol databases - filtered.data <- fetchagol::fetchRawData(agol_url_dict[[data.name]], "mojn_data") + # Read AGOL data + filtered.data <- fetchagol::fetchRawData(GetAGOLInfo()[[data.name]], "mojn_data") filtered.data <- fetchagol::cleanData(filtered.data) filtered.data <- filtered.data$data } else if (data.source == "local") { @@ -579,6 +591,7 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data #' @param create.folders Should \code{dest.folder} be created automatically if it doesn't exist? Defaults to \code{FALSE}. #' @param overwrite Should existing data be automatically overwritten? Defaults to \code{FALSE}. #' @param aquarius Include Aquarius data? +#' @param agol Include AGOL data? #' @param calculated Include calculated data (median stream wq, median lake wq, and lake surface elevation)? #' #' @return None. @@ -590,9 +603,10 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data #' SaveDataToCsv(conn, "C:/Users/myusername/Documents/R/streamsandlakes-data", TRUE, TRUE) #' CloseDatabaseConnection(conn) #' } -SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, calculated = TRUE) { +SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, agol = FALSE, calculated = TRUE) { analysis.views <- names(GetColSpec()) aq.data <- names(GetAquariusColSpec()) + agol.databases <- hash::keys(GetAGOLInfo()) dest.folder <- file.path(dirname(dest.folder), basename(dest.folder)) # Get destination directory in a consistent format. Seems like there should be a better way to do this. file.paths <- c(file.path(dest.folder, paste0(analysis.views, ".csv")), file.path(dest.folder, paste0(aq.data, ".csv"))) @@ -653,6 +667,53 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = } } + if(agol){ + + for (agol.name in agol.databases) { + # tryCatch( + # { + # df <- ReadAquarius(conn, aq.name) + + raw_df <- fetchagol::fetchRawData(GetAGOLInfo()[[agol.name]], "mojn_data") + raw_df <- fetchagol::cleanData(raw_df) + + # TODO update this so its nicer/more dynamic - maybe put in a function + if(agol.name == "BMI"){ + df <- list( + BMI_Metrics = raw_df$data$BMI_Metrics, + BMI_Species = raw_df$data$BMI_Species, + BMI_SiteVisit = raw_df$data$BMI_SiteVisit + ) + # $BMI_Metrics <- raw_df$data$BMI_Metrics + # df$BMI_Species <- raw_df$data$BMI_Species + } else { + df <- raw_df$data + } + + + for (i in 1:length(df)) { + + # Include time zone in dates + # if("DateTime" %in% names(df)) { + # df$DateTime <- format(df$DateTime, "%y-%m-%d %H:%M:%S %z") + # } + readr::write_csv(df[[i]], file.path(dest.folder, paste0(names(df)[i], ".csv")), na = "", append = FALSE, col_names = TRUE) + + } + + + # }, + # error = function(e) { + # if (e$message == "Aquarius connection does not exist.") { + # warning(paste0("Could not connect to Aquarius. Skipping", aq.name, ".csv")) + # } + # else {e} + # } + # ) + } + + } + } #' Raw data dump @@ -876,3 +937,41 @@ expect_dataframe_equal <- function(result, expected, ignore_col_order = FALSE, i return(testthat::expect_true(test_result, label = test_result)) } + + +#' Fetch BMI data from AGOL and do preliminary data wrangling +#' +#' @param bmi_url URL to AGOL BMI database +#' @param agol_username Authentication token (not needed for public layers) +#' +#' @return A list of data frames and metadata +#' @export +fetchAndWrangleBMI <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + agol_username = "mojn_data") { + # Import BMI database + raw_data <- fetchagol::fetchRawData(bmi_url, agol_username) + raw_data <- fetchagol::cleanData(raw_data) + + # Remove unwanted data and metadata + raw_data$data[['BMI_Metadata']] <- NULL + raw_data$metadata[['BMI_Metadata']] <- NULL + + invisible(raw_data) +} + + +#' Write BMI data to CSV +#' +#' @inheritParams fetchagol::writeToFiles +#' +#' @export +writeBMI <- function(all_data, data_dir = here::here("data", "final"), dictionary_dir = here::here("data", "dictionary"), + dictionary_filenames = c(tables = "data_dictionary_tables.txt", + attributes = "data_dictionary_attributes.txt", + categories = "data_dictionary_categories.txt"), + verbose = FALSE, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator"), ...) +{ + fetchagol::writeToFiles(all_data = all_data, data_dir = data_dir, dictionary_dir = dictionary_dir, lookup_dir = NA, verbose = verbose, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator")) +} + + From 7bb031dc1e7dc2ba2be878b75d265381f27d378f Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Thu, 21 Mar 2024 11:08:04 -0700 Subject: [PATCH 05/27] adding loading and writing bmi functions --- R/utils.R | 163 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 65 deletions(-) diff --git a/R/utils.R b/R/utils.R index 2ee9f0d..3454f5d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -78,71 +78,71 @@ GetColSpec <- function() { DataStoreReferenceCode = readr::col_integer(), .default = readr::col_character() ), - BMI = readr::cols( - VisitDate = readr::col_date(), - DateCollected = readr::col_date(), - FieldSplit = readr::col_integer(), - LabSplit = readr::col_double(), - SampleArea_m2 = readr::col_double(), - Abundance = readr::col_integer(), - Richness = readr::col_integer(), - DominantTaxaPercent = readr::col_double(), - SplitCount = readr::col_integer(), - FixedCount = readr::col_integer(), - BigRareCount = readr::col_integer(), - ShannonsDiversity = readr::col_double(), - SimpsonsDiversity = readr::col_double(), - Evenness = readr::col_double(), - EPTTaxaCount = readr::col_integer(), - EPTTaxaAbundance = readr::col_integer(), - DominantFamilyAbundance = readr::col_integer(), - DominantTaxaAbundance = readr::col_integer(), - Hilsenhoff = readr::col_double(), - IntolerantTaxaCount = readr::col_integer(), - IntolerantTaxaAbundance = readr::col_integer(), - TolerantTaxaCount = readr::col_integer(), - TolerantTaxaAbundance = readr::col_integer(), - USFSCommunityToleranceQuo = readr::col_integer(), - ShredderTaxaCount = readr::col_integer(), - ShredderAbundance = readr::col_integer(), - ScraperTaxaCount = readr::col_integer(), - ScraperAbundance = readr::col_integer(), - CollectorFiltererCount = readr::col_integer(), - CollectorFiltererAbundance = readr::col_integer(), - CollectorGathererCount = readr::col_integer(), - CollectorGathererAbundance = readr::col_integer(), - PredatorTaxaCount = readr::col_integer(), - PredatorTaxaAbundance = readr::col_integer(), - ClingerTaxaCount = readr::col_integer(), - LongLivedTaxa = readr::col_integer(), - EphemeropteraTaxaCount = readr::col_integer(), - EphemeropteraTaxaAbundance = readr::col_integer(), - PlecopteraTaxa = readr::col_integer(), - PlecopteraTaxaAbundance = readr::col_integer(), - TrichopteraTaxaCount = readr::col_integer(), - TrichopteraAbundance = readr::col_integer(), - ColeopteraTaxaCount = readr::col_integer(), - ColeopteraAbundance = readr::col_integer(), - ElmidaeTaxaCount = readr::col_integer(), - ElmidaeAbundance = readr::col_integer(), - MegalopteraTaxaCount = readr::col_integer(), - MegalopteraAbundance = readr::col_integer(), - DipteraTaxaCount = readr::col_integer(), - DipteraAbundance = readr::col_integer(), - ChironomidaeTaxaCount = readr::col_integer(), - ChironomidaeAbundance = readr::col_integer(), - CrustaceaTaxaCount = readr::col_integer(), - CrustaceaAbundance = readr::col_integer(), - OligochaeteTaxaCount = readr::col_integer(), - OligochaeteAbundance = readr::col_integer(), - MolluscaTaxaCount = readr::col_integer(), - MolluscaAbundance = readr::col_integer(), - InsectTaxaCount = readr::col_integer(), - InsectAbundance = readr::col_integer(), - NonInsectTaxaCount = readr::col_integer(), - NonInsectAbundance = readr::col_integer(), - .default = readr::col_character() - ), + # BMI = readr::cols( + # VisitDate = readr::col_date(), + # DateCollected = readr::col_date(), + # FieldSplit = readr::col_integer(), + # LabSplit = readr::col_double(), + # SampleArea_m2 = readr::col_double(), + # Abundance = readr::col_integer(), + # Richness = readr::col_integer(), + # DominantTaxaPercent = readr::col_double(), + # SplitCount = readr::col_integer(), + # FixedCount = readr::col_integer(), + # BigRareCount = readr::col_integer(), + # ShannonsDiversity = readr::col_double(), + # SimpsonsDiversity = readr::col_double(), + # Evenness = readr::col_double(), + # EPTTaxaCount = readr::col_integer(), + # EPTTaxaAbundance = readr::col_integer(), + # DominantFamilyAbundance = readr::col_integer(), + # DominantTaxaAbundance = readr::col_integer(), + # Hilsenhoff = readr::col_double(), + # IntolerantTaxaCount = readr::col_integer(), + # IntolerantTaxaAbundance = readr::col_integer(), + # TolerantTaxaCount = readr::col_integer(), + # TolerantTaxaAbundance = readr::col_integer(), + # USFSCommunityToleranceQuo = readr::col_integer(), + # ShredderTaxaCount = readr::col_integer(), + # ShredderAbundance = readr::col_integer(), + # ScraperTaxaCount = readr::col_integer(), + # ScraperAbundance = readr::col_integer(), + # CollectorFiltererCount = readr::col_integer(), + # CollectorFiltererAbundance = readr::col_integer(), + # CollectorGathererCount = readr::col_integer(), + # CollectorGathererAbundance = readr::col_integer(), + # PredatorTaxaCount = readr::col_integer(), + # PredatorTaxaAbundance = readr::col_integer(), + # ClingerTaxaCount = readr::col_integer(), + # LongLivedTaxa = readr::col_integer(), + # EphemeropteraTaxaCount = readr::col_integer(), + # EphemeropteraTaxaAbundance = readr::col_integer(), + # PlecopteraTaxa = readr::col_integer(), + # PlecopteraTaxaAbundance = readr::col_integer(), + # TrichopteraTaxaCount = readr::col_integer(), + # TrichopteraAbundance = readr::col_integer(), + # ColeopteraTaxaCount = readr::col_integer(), + # ColeopteraAbundance = readr::col_integer(), + # ElmidaeTaxaCount = readr::col_integer(), + # ElmidaeAbundance = readr::col_integer(), + # MegalopteraTaxaCount = readr::col_integer(), + # MegalopteraAbundance = readr::col_integer(), + # DipteraTaxaCount = readr::col_integer(), + # DipteraAbundance = readr::col_integer(), + # ChironomidaeTaxaCount = readr::col_integer(), + # ChironomidaeAbundance = readr::col_integer(), + # CrustaceaTaxaCount = readr::col_integer(), + # CrustaceaAbundance = readr::col_integer(), + # OligochaeteTaxaCount = readr::col_integer(), + # OligochaeteAbundance = readr::col_integer(), + # MolluscaTaxaCount = readr::col_integer(), + # MolluscaAbundance = readr::col_integer(), + # InsectTaxaCount = readr::col_integer(), + # InsectAbundance = readr::col_integer(), + # NonInsectTaxaCount = readr::col_integer(), + # NonInsectAbundance = readr::col_integer(), + # .default = readr::col_character() + # ), Channel = readr::cols( VisitDate = readr::col_date(), .default = readr::col_character() @@ -974,4 +974,37 @@ writeBMI <- function(all_data, data_dir = here::here("data", "final"), dictionar fetchagol::writeToFiles(all_data = all_data, data_dir = data_dir, dictionary_dir = dictionary_dir, lookup_dir = NA, verbose = verbose, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator")) } +#' Fetch BMI data from AGOL and do preliminary data wrangling +#' +#' @param bmi_url URL to AGOL BMI database +#' @param agol_username Authentication token (not needed for public layers) +#' +#' @return A list of data frames and metadata +#' @export +fetchAndWrangleBMI <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + agol_username = "mojn_data") { + # Import BMI database + raw_data <- fetchagol::fetchRawData(bmi_url, agol_username) + raw_data <- fetchagol::cleanData(raw_data) + + # Remove unwanted data and metadata + raw_data$data[['BMI_Metadata']] <- NULL + raw_data$metadata[['BMI_Metadata']] <- NULL + + invisible(raw_data) +} + +#' Write BMI data to CSV +#' +#' @inheritParams fetchagol::writeToFiles +#' +#' @export +writeBMI <- function(all_data, data_dir = here::here("data", "final"), dictionary_dir = here::here("data", "dictionary"), + dictionary_filenames = c(tables = "data_dictionary_tables.txt", + attributes = "data_dictionary_attributes.txt", + categories = "data_dictionary_categories.txt"), + verbose = FALSE, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator"), ...) +{ + fetchagol::writeToFiles(all_data = all_data, data_dir = data_dir, dictionary_dir = dictionary_dir, lookup_dir = NA, verbose = verbose, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator")) +} From 06ea4c656ae29cda74152117aa8fdd71c2720453 Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Thu, 21 Mar 2024 11:40:50 -0700 Subject: [PATCH 06/27] updating man files --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ man/QCBenchmarkElevation.Rd | 46 ------------------------------ man/QcBMIDiscrepancies.Rd | 43 ---------------------------- man/QcStringSurveyElevations.Rd | 46 ------------------------------ man/QcStringSurveyHeights.Rd | 46 ------------------------------ man/QcWqCleaned.Rd | 37 ------------------------ man/QcWqFlags.Rd | 37 ------------------------ man/QcWqSanity.Rd | 37 ------------------------ man/SaveDataToCsv.Rd | 3 ++ man/fetchAndWrangleBMI.Rd | 33 ++++++++++++++++++++++ man/writeBMI.Rd | 50 +++++++++++++++++++++++++++++++++ 12 files changed, 89 insertions(+), 293 deletions(-) delete mode 100644 man/QCBenchmarkElevation.Rd delete mode 100644 man/QcBMIDiscrepancies.Rd delete mode 100644 man/QcStringSurveyElevations.Rd delete mode 100644 man/QcStringSurveyHeights.Rd delete mode 100644 man/QcWqCleaned.Rd delete mode 100644 man/QcWqFlags.Rd delete mode 100644 man/QcWqSanity.Rd create mode 100644 man/fetchAndWrangleBMI.Rd create mode 100644 man/writeBMI.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 985d01e..02928cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,7 @@ Imports: measurements, statip, stringr -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.1 Suggests: testthat, roxygen2 diff --git a/NAMESPACE b/NAMESPACE index f434daa..b4be1fb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,6 +38,7 @@ export(WqPlotPHDepthProfile) export(WqPlotSpCondDepthProfile) export(WqPlotTemperatureDepthProfile) export(expect_dataframe_equal) +export(fetchAndWrangleBMI) export(getMDLLookup) export(qcBMIDiscrepancies) export(qcBenchmarkElevation) @@ -72,6 +73,7 @@ export(qcWqCompletenessPlot) export(qcWqGrades) export(qcWqGradesLong) export(qcWqGradesPlot) +export(writeBMI) importFrom(magrittr,"%<>%") importFrom(magrittr,"%>%") importFrom(stats,median) diff --git a/man/QCBenchmarkElevation.Rd b/man/QCBenchmarkElevation.Rd deleted file mode 100644 index 6bcd416..0000000 --- a/man/QCBenchmarkElevation.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/levels-qc.R -\name{qcBenchmarkElevation} -\alias{qcBenchmarkElevation} -\title{Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons} -\usage{ -qcBenchmarkElevation( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} -} -\value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, Benchmark, MeanElevation_ft, StDevElevation_ft. -} -\description{ -Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons -} -\examples{ -\dontrun{ - conn <- OpenDatabaseConnection() - qcBenchmarkElevation(conn) - qcBenchmarkElevation(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) - qcBenchmarkElevation(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) -} -} diff --git a/man/QcBMIDiscrepancies.Rd b/man/QcBMIDiscrepancies.Rd deleted file mode 100644 index 0b5ddef..0000000 --- a/man/QcBMIDiscrepancies.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bmi-qc.R -\name{qcBMIDiscrepancies} -\alias{qcBMIDiscrepancies} -\title{Check for discrepancies between taxa count and abundance} -\usage{ -qcBMIDiscrepancies( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} -} -\value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupCount, TaxaGroupAbundance, LabNotes. -} -\description{ -Check for discrepancies between taxa count and abundance -} -\examples{ -\dontrun{ -c <- OpenDatabaseConnection -bmi_issues <- qcBMIDiscrepancies(c) # Get all instances of discrepancy between taxa count and abundance -bmi_issues_mill <- qcBMIDiscrepancies(c, site = "GRBA_S_MILL1") # Look at issues for Mill Creek only -bmi_issues_bakr_2015 <- qcBMIDiscrepancies(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") # Look at issues for Baker Creek sites in 2015 -CloseDatabaseConnection(c) -} -} diff --git a/man/QcStringSurveyElevations.Rd b/man/QcStringSurveyElevations.Rd deleted file mode 100644 index fd2c251..0000000 --- a/man/QcStringSurveyElevations.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/levels-qc.R -\name{qcStringSurveyElevations} -\alias{qcStringSurveyElevations} -\title{Calculates mean and standard deviation of string survey lake level elevations for each year} -\usage{ -qcStringSurveyElevations( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} -} -\value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanFinalElevation_ft, StDevFinalElevation_ft -} -\description{ -Calculates mean and standard deviation of string survey lake level elevations for each year -} -\examples{ -\dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyElevations(conn) - qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) - qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) -} -} diff --git a/man/QcStringSurveyHeights.Rd b/man/QcStringSurveyHeights.Rd deleted file mode 100644 index 74a84ef..0000000 --- a/man/QcStringSurveyHeights.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/levels-qc.R -\name{qcStringSurveyHeights} -\alias{qcStringSurveyHeights} -\title{Calculates mean and standard deviation of string survey heights for each benchmark} -\usage{ -qcStringSurveyHeights( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} -} -\value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanHeight_ft, StDevHeight_ft -} -\description{ -Calculates mean and standard deviation of string survey heights for each benchmark -} -\examples{ -\dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyHeights(conn) - qcStringSurveyHeights(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) - qcStringSurveyHeights(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) -} -} diff --git a/man/QcWqCleaned.Rd b/man/QcWqCleaned.Rd deleted file mode 100644 index 49a4254..0000000 --- a/man/QcWqCleaned.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/wq-qc.R -\name{qcWqCleaned} -\alias{qcWqCleaned} -\title{Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags.} -\usage{ -qcWqCleaned( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} -} -\value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. -} -\description{ -Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags. -} diff --git a/man/QcWqFlags.Rd b/man/QcWqFlags.Rd deleted file mode 100644 index 06eec02..0000000 --- a/man/QcWqFlags.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/wq-qc.R -\name{qcWqFlags} -\alias{qcWqFlags} -\title{Compile list of water quality values that have data quality flags.} -\usage{ -qcWqFlags( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} -} -\value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. -} -\description{ -Compile list of water quality values that have data quality flags. -} diff --git a/man/QcWqSanity.Rd b/man/QcWqSanity.Rd deleted file mode 100644 index 0c15942..0000000 --- a/man/QcWqSanity.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/wq-qc.R -\name{qcWqSanity} -\alias{qcWqSanity} -\title{Water quality sanity check} -\usage{ -qcWqSanity( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - -\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} -} -\value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. -} -\description{ -Perform sanity check and compile list of potentially incorrect or outlier water quality values. This function is not exported; instead it is called by StreamQcWqSanity and LakeQcWqSanity -} diff --git a/man/SaveDataToCsv.Rd b/man/SaveDataToCsv.Rd index a1dfb9b..6c8dc39 100644 --- a/man/SaveDataToCsv.Rd +++ b/man/SaveDataToCsv.Rd @@ -10,6 +10,7 @@ SaveDataToCsv( create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, + agol = FALSE, calculated = TRUE ) } @@ -24,6 +25,8 @@ SaveDataToCsv( \item{aquarius}{Include Aquarius data?} +\item{agol}{Include AGOL data?} + \item{calculated}{Include calculated data (median stream wq, median lake wq, and lake surface elevation)?} } \value{ diff --git a/man/fetchAndWrangleBMI.Rd b/man/fetchAndWrangleBMI.Rd new file mode 100644 index 0000000..6df4fe7 --- /dev/null +++ b/man/fetchAndWrangleBMI.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{fetchAndWrangleBMI} +\alias{fetchAndWrangleBMI} +\title{Fetch BMI data from AGOL and do preliminary data wrangling} +\usage{ +fetchAndWrangleBMI( + bmi_url = + "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + agol_username = "mojn_data" +) + +fetchAndWrangleBMI( + bmi_url = + "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + agol_username = "mojn_data" +) +} +\arguments{ +\item{bmi_url}{URL to AGOL BMI database} + +\item{agol_username}{Authentication token (not needed for public layers)} +} +\value{ +A list of data frames and metadata + +A list of data frames and metadata +} +\description{ +Fetch BMI data from AGOL and do preliminary data wrangling + +Fetch BMI data from AGOL and do preliminary data wrangling +} diff --git a/man/writeBMI.Rd b/man/writeBMI.Rd new file mode 100644 index 0000000..b465248 --- /dev/null +++ b/man/writeBMI.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{writeBMI} +\alias{writeBMI} +\title{Write BMI data to CSV} +\usage{ +writeBMI( + all_data, + data_dir = here::here("data", "final"), + dictionary_dir = here::here("data", "dictionary"), + dictionary_filenames = c(tables = "data_dictionary_tables.txt", attributes = + "data_dictionary_attributes.txt", categories = "data_dictionary_categories.txt"), + verbose = FALSE, + removeColumns = TRUE, + cols_to_remove = c("Editor", "Creator"), + ... +) + +writeBMI( + all_data, + data_dir = here::here("data", "final"), + dictionary_dir = here::here("data", "dictionary"), + dictionary_filenames = c(tables = "data_dictionary_tables.txt", attributes = + "data_dictionary_attributes.txt", categories = "data_dictionary_categories.txt"), + verbose = FALSE, + removeColumns = TRUE, + cols_to_remove = c("Editor", "Creator"), + ... +) +} +\arguments{ +\item{all_data}{Output of \code{fetchRawData()}} + +\item{data_dir}{Folder to store data csv's in} + +\item{dictionary_dir}{Folder to store data dictionaries in} + +\item{dictionary_filenames}{Named list with names \code{c("tables", "attributes", "categories")} indicating what to name the tables, attributes, and categories data dictionaries. You are encouraged to keep the default names unless you have a good reason to change them.} + +\item{verbose}{Output feedback to console?} + +\item{removeColumns}{Should columns be removed?} + +\item{cols_to_remove}{Columns that should be removed, \code{c("Editor", "Creator")} is the default because they can contain personally identifiable information} +} +\description{ +Write BMI data to CSV + +Write BMI data to CSV +} From 4f0c83b3ceb7faa79195422cd962ad219492b018 Mon Sep 17 00:00:00 2001 From: Irene Foster Date: Thu, 21 Mar 2024 12:58:16 -0700 Subject: [PATCH 07/27] remove BMI stuff from SQL functions --- R/utils.R | 158 +------------------------------- man/SaveDataToCsv.Rd | 3 - man/fetchAndWrangleBMI.Rd | 10 -- man/qcBMIDiscrepancies.Rd | 43 +++++++++ man/qcBenchmarkElevation.Rd | 46 ++++++++++ man/qcStringSurveyElevations.Rd | 46 ++++++++++ man/qcStringSurveyHeights.Rd | 46 ++++++++++ man/qcWqCleaned.Rd | 37 ++++++++ man/qcWqFlags.Rd | 37 ++++++++ man/qcWqSanity.Rd | 37 ++++++++ man/writeBMI.Rd | 14 --- 11 files changed, 294 insertions(+), 183 deletions(-) create mode 100644 man/qcBMIDiscrepancies.Rd create mode 100644 man/qcBenchmarkElevation.Rd create mode 100644 man/qcStringSurveyElevations.Rd create mode 100644 man/qcStringSurveyHeights.Rd create mode 100644 man/qcWqCleaned.Rd create mode 100644 man/qcWqFlags.Rd create mode 100644 man/qcWqSanity.Rd diff --git a/R/utils.R b/R/utils.R index 3454f5d..de99606 100644 --- a/R/utils.R +++ b/R/utils.R @@ -256,17 +256,6 @@ GetAquariusColSpec <- function() { return(col.spec.aq) } -#' Get AGOL databases and their URLs -#' -#' @param agol_url_dict A dictionary of database names and URLs -#' -#' @returns A dict where keys are databases in AGOL and the values are the associated database URLs -#' -#' TODO add info about columns?? -GetAGOLInfo <- function(agol_url_dict = hash::hash(keys = c("BMI"), values = c("https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer"))) { - return(agol_url_dict) -} - #' Read Streams and Lakes data from Aquarius #' #' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. @@ -473,10 +462,7 @@ ReadAquariusLakes <- function(conn, data.name) { ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name) { col.spec <- GetColSpec() col.spec.aq <- GetAquariusColSpec() - col.spec.agol <- hash::keys(GetAGOLInfo()) - #col.spec.agol <- c("BMI") - # TODO add agol stuff to this list correctly - col.spec.all <- c(col.spec, col.spec.aq, col.spec.agol) + col.spec.all <- c(col.spec, col.spec.aq) if (!(data.source %in% c("database", "local"))) { stop("Please choose either 'database' or 'local' for data.source") @@ -491,11 +477,6 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } else if (data.source == "database" & data.name %in% names(col.spec.aq)) { ## Read Aquarius data filtered.data <- ReadAquarius(conn, data.name) - } else if (data.source == "database" & data.name %in% col.spec.agol) { - # Read AGOL data - filtered.data <- fetchagol::fetchRawData(GetAGOLInfo()[[data.name]], "mojn_data") - filtered.data <- fetchagol::cleanData(filtered.data) - filtered.data <- filtered.data$data } else if (data.source == "local") { filtered.data <- readr::read_csv(file.path(path.to.data, paste0(data.name, ".csv")), na = "", col_types = col.spec.all[[data.name]], lazy = FALSE) if(data.name %in% names(col.spec.aq) & "DateTime" %in% names(filtered.data)) { @@ -503,54 +484,6 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data } } - # Filtering for data from AGOL - if (data.name %in% col.spec.agol) { - if (!missing(park)) { - - filtered.data <- lapply(filtered.data, function(table){ - # If the table has a Park column filter for specified park - if("Park" %in% colnames(table)) { - table <- table %>% dplyr::filter(Park == park) - } - if (nrow(table) == 0) { - warning(paste0(data.name, ": Data are not available for the park specified")) - } - return(table) - })} - - if (!missing(site) & length(filtered.data) > 0) { - # If the table has a SiteCode column filter for specified site - filtered.data <- lapply(filtered.data, function(table){ - if("SiteCode" %in% colnames(table)) { - table <- table %>% dplyr::filter(SiteCode %in% site) - - } - if (nrow(table) == 0) { - warning(paste0(data.name, ": Data are not available for the site specified")) - } - return(table) - })} - - # TODO: I dont think this is necessary for the AGOL data - # if ("FieldSeason" %in% names(filtered.data)) { - # filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) - # } - - if (!missing(field.season) & length(filtered.data) > 0) { - - # If the table has a SiteCode column filter for specified site - filtered.data <- lapply(filtered.data, function(table){ - if("FieldSeason" %in% colnames(table)) { - table <- table %>% dplyr::filter(FieldSeason %in% field.season) - - } - if (nrow(table) == 0) { - warning(paste0(data.name, ": Data are not available for the field season specified")) - } - return(table) - })} - # Filtering for any other data source besides AGOL - } else{ if (!missing(park)) { filtered.data %<>% dplyr::filter(Park == park) @@ -579,7 +512,6 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data warning(paste0(data.name, ": Data are not available for one or more of the field seasons specified")) } } - } return(filtered.data) } @@ -591,7 +523,6 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data #' @param create.folders Should \code{dest.folder} be created automatically if it doesn't exist? Defaults to \code{FALSE}. #' @param overwrite Should existing data be automatically overwritten? Defaults to \code{FALSE}. #' @param aquarius Include Aquarius data? -#' @param agol Include AGOL data? #' @param calculated Include calculated data (median stream wq, median lake wq, and lake surface elevation)? #' #' @return None. @@ -603,10 +534,9 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data #' SaveDataToCsv(conn, "C:/Users/myusername/Documents/R/streamsandlakes-data", TRUE, TRUE) #' CloseDatabaseConnection(conn) #' } -SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, agol = FALSE, calculated = TRUE) { +SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, calculated = TRUE) { analysis.views <- names(GetColSpec()) aq.data <- names(GetAquariusColSpec()) - agol.databases <- hash::keys(GetAGOLInfo()) dest.folder <- file.path(dirname(dest.folder), basename(dest.folder)) # Get destination directory in a consistent format. Seems like there should be a better way to do this. file.paths <- c(file.path(dest.folder, paste0(analysis.views, ".csv")), file.path(dest.folder, paste0(aq.data, ".csv"))) @@ -666,54 +596,6 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = ) } } - - if(agol){ - - for (agol.name in agol.databases) { - # tryCatch( - # { - # df <- ReadAquarius(conn, aq.name) - - raw_df <- fetchagol::fetchRawData(GetAGOLInfo()[[agol.name]], "mojn_data") - raw_df <- fetchagol::cleanData(raw_df) - - # TODO update this so its nicer/more dynamic - maybe put in a function - if(agol.name == "BMI"){ - df <- list( - BMI_Metrics = raw_df$data$BMI_Metrics, - BMI_Species = raw_df$data$BMI_Species, - BMI_SiteVisit = raw_df$data$BMI_SiteVisit - ) - # $BMI_Metrics <- raw_df$data$BMI_Metrics - # df$BMI_Species <- raw_df$data$BMI_Species - } else { - df <- raw_df$data - } - - - for (i in 1:length(df)) { - - # Include time zone in dates - # if("DateTime" %in% names(df)) { - # df$DateTime <- format(df$DateTime, "%y-%m-%d %H:%M:%S %z") - # } - readr::write_csv(df[[i]], file.path(dest.folder, paste0(names(df)[i], ".csv")), na = "", append = FALSE, col_names = TRUE) - - } - - - # }, - # error = function(e) { - # if (e$message == "Aquarius connection does not exist.") { - # warning(paste0("Could not connect to Aquarius. Skipping", aq.name, ".csv")) - # } - # else {e} - # } - # ) - } - - } - } #' Raw data dump @@ -938,42 +820,6 @@ expect_dataframe_equal <- function(result, expected, ignore_col_order = FALSE, i return(testthat::expect_true(test_result, label = test_result)) } - -#' Fetch BMI data from AGOL and do preliminary data wrangling -#' -#' @param bmi_url URL to AGOL BMI database -#' @param agol_username Authentication token (not needed for public layers) -#' -#' @return A list of data frames and metadata -#' @export -fetchAndWrangleBMI <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", - agol_username = "mojn_data") { - # Import BMI database - raw_data <- fetchagol::fetchRawData(bmi_url, agol_username) - raw_data <- fetchagol::cleanData(raw_data) - - # Remove unwanted data and metadata - raw_data$data[['BMI_Metadata']] <- NULL - raw_data$metadata[['BMI_Metadata']] <- NULL - - invisible(raw_data) -} - - -#' Write BMI data to CSV -#' -#' @inheritParams fetchagol::writeToFiles -#' -#' @export -writeBMI <- function(all_data, data_dir = here::here("data", "final"), dictionary_dir = here::here("data", "dictionary"), - dictionary_filenames = c(tables = "data_dictionary_tables.txt", - attributes = "data_dictionary_attributes.txt", - categories = "data_dictionary_categories.txt"), - verbose = FALSE, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator"), ...) -{ - fetchagol::writeToFiles(all_data = all_data, data_dir = data_dir, dictionary_dir = dictionary_dir, lookup_dir = NA, verbose = verbose, removeColumns = TRUE, cols_to_remove = c("Editor", "Creator")) -} - #' Fetch BMI data from AGOL and do preliminary data wrangling #' #' @param bmi_url URL to AGOL BMI database diff --git a/man/SaveDataToCsv.Rd b/man/SaveDataToCsv.Rd index 6c8dc39..a1dfb9b 100644 --- a/man/SaveDataToCsv.Rd +++ b/man/SaveDataToCsv.Rd @@ -10,7 +10,6 @@ SaveDataToCsv( create.folders = FALSE, overwrite = FALSE, aquarius = TRUE, - agol = FALSE, calculated = TRUE ) } @@ -25,8 +24,6 @@ SaveDataToCsv( \item{aquarius}{Include Aquarius data?} -\item{agol}{Include AGOL data?} - \item{calculated}{Include calculated data (median stream wq, median lake wq, and lake surface elevation)?} } \value{ diff --git a/man/fetchAndWrangleBMI.Rd b/man/fetchAndWrangleBMI.Rd index 6df4fe7..c523c16 100644 --- a/man/fetchAndWrangleBMI.Rd +++ b/man/fetchAndWrangleBMI.Rd @@ -4,12 +4,6 @@ \alias{fetchAndWrangleBMI} \title{Fetch BMI data from AGOL and do preliminary data wrangling} \usage{ -fetchAndWrangleBMI( - bmi_url = - "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", - agol_username = "mojn_data" -) - fetchAndWrangleBMI( bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", @@ -22,12 +16,8 @@ fetchAndWrangleBMI( \item{agol_username}{Authentication token (not needed for public layers)} } \value{ -A list of data frames and metadata - A list of data frames and metadata } \description{ -Fetch BMI data from AGOL and do preliminary data wrangling - Fetch BMI data from AGOL and do preliminary data wrangling } diff --git a/man/qcBMIDiscrepancies.Rd b/man/qcBMIDiscrepancies.Rd new file mode 100644 index 0000000..0b5ddef --- /dev/null +++ b/man/qcBMIDiscrepancies.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bmi-qc.R +\name{qcBMIDiscrepancies} +\alias{qcBMIDiscrepancies} +\title{Check for discrepancies between taxa count and abundance} +\usage{ +qcBMIDiscrepancies( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database" +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} +} +\value{ +A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupCount, TaxaGroupAbundance, LabNotes. +} +\description{ +Check for discrepancies between taxa count and abundance +} +\examples{ +\dontrun{ +c <- OpenDatabaseConnection +bmi_issues <- qcBMIDiscrepancies(c) # Get all instances of discrepancy between taxa count and abundance +bmi_issues_mill <- qcBMIDiscrepancies(c, site = "GRBA_S_MILL1") # Look at issues for Mill Creek only +bmi_issues_bakr_2015 <- qcBMIDiscrepancies(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") # Look at issues for Baker Creek sites in 2015 +CloseDatabaseConnection(c) +} +} diff --git a/man/qcBenchmarkElevation.Rd b/man/qcBenchmarkElevation.Rd new file mode 100644 index 0000000..6bcd416 --- /dev/null +++ b/man/qcBenchmarkElevation.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{qcBenchmarkElevation} +\alias{qcBenchmarkElevation} +\title{Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons} +\usage{ +qcBenchmarkElevation( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + sd_cutoff = NA +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} +} +\value{ +A tibble with columns Park, SiteShort, SiteCode, SiteName, Benchmark, MeanElevation_ft, StDevElevation_ft. +} +\description{ +Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons +} +\examples{ +\dontrun{ + conn <- OpenDatabaseConnection() + qcBenchmarkElevation(conn) + qcBenchmarkElevation(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) + qcBenchmarkElevation(path.to.data = "path/to/data", data.source = "local") + CloseDatabaseConnection(conn) +} +} diff --git a/man/qcStringSurveyElevations.Rd b/man/qcStringSurveyElevations.Rd new file mode 100644 index 0000000..fd2c251 --- /dev/null +++ b/man/qcStringSurveyElevations.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{qcStringSurveyElevations} +\alias{qcStringSurveyElevations} +\title{Calculates mean and standard deviation of string survey lake level elevations for each year} +\usage{ +qcStringSurveyElevations( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + sd_cutoff = NA +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} +} +\value{ +A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanFinalElevation_ft, StDevFinalElevation_ft +} +\description{ +Calculates mean and standard deviation of string survey lake level elevations for each year +} +\examples{ +\dontrun{ + conn <- OpenDatabaseConnection() + qcStringSurveyElevations(conn) + qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) + qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") + CloseDatabaseConnection(conn) +} +} diff --git a/man/qcStringSurveyHeights.Rd b/man/qcStringSurveyHeights.Rd new file mode 100644 index 0000000..74a84ef --- /dev/null +++ b/man/qcStringSurveyHeights.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{qcStringSurveyHeights} +\alias{qcStringSurveyHeights} +\title{Calculates mean and standard deviation of string survey heights for each benchmark} +\usage{ +qcStringSurveyHeights( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + sd_cutoff = NA +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} +} +\value{ +A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanHeight_ft, StDevHeight_ft +} +\description{ +Calculates mean and standard deviation of string survey heights for each benchmark +} +\examples{ +\dontrun{ + conn <- OpenDatabaseConnection() + qcStringSurveyHeights(conn) + qcStringSurveyHeights(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) + qcStringSurveyHeights(path.to.data = "path/to/data", data.source = "local") + CloseDatabaseConnection(conn) +} +} diff --git a/man/qcWqCleaned.Rd b/man/qcWqCleaned.Rd new file mode 100644 index 0000000..49a4254 --- /dev/null +++ b/man/qcWqCleaned.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/wq-qc.R +\name{qcWqCleaned} +\alias{qcWqCleaned} +\title{Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags.} +\usage{ +qcWqCleaned( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + wq.type +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} +} +\value{ +A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +} +\description{ +Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags. +} diff --git a/man/qcWqFlags.Rd b/man/qcWqFlags.Rd new file mode 100644 index 0000000..06eec02 --- /dev/null +++ b/man/qcWqFlags.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/wq-qc.R +\name{qcWqFlags} +\alias{qcWqFlags} +\title{Compile list of water quality values that have data quality flags.} +\usage{ +qcWqFlags( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + wq.type +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} +} +\value{ +A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +} +\description{ +Compile list of water quality values that have data quality flags. +} diff --git a/man/qcWqSanity.Rd b/man/qcWqSanity.Rd new file mode 100644 index 0000000..0c15942 --- /dev/null +++ b/man/qcWqSanity.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/wq-qc.R +\name{qcWqSanity} +\alias{qcWqSanity} +\title{Water quality sanity check} +\usage{ +qcWqSanity( + conn, + path.to.data, + park, + site, + field.season, + data.source = "database", + wq.type +) +} +\arguments{ +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} + +\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} +} +\value{ +A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +} +\description{ +Perform sanity check and compile list of potentially incorrect or outlier water quality values. This function is not exported; instead it is called by StreamQcWqSanity and LakeQcWqSanity +} diff --git a/man/writeBMI.Rd b/man/writeBMI.Rd index b465248..afb4e7e 100644 --- a/man/writeBMI.Rd +++ b/man/writeBMI.Rd @@ -4,18 +4,6 @@ \alias{writeBMI} \title{Write BMI data to CSV} \usage{ -writeBMI( - all_data, - data_dir = here::here("data", "final"), - dictionary_dir = here::here("data", "dictionary"), - dictionary_filenames = c(tables = "data_dictionary_tables.txt", attributes = - "data_dictionary_attributes.txt", categories = "data_dictionary_categories.txt"), - verbose = FALSE, - removeColumns = TRUE, - cols_to_remove = c("Editor", "Creator"), - ... -) - writeBMI( all_data, data_dir = here::here("data", "final"), @@ -44,7 +32,5 @@ writeBMI( \item{cols_to_remove}{Columns that should be removed, \code{c("Editor", "Creator")} is the default because they can contain personally identifiable information} } \description{ -Write BMI data to CSV - Write BMI data to CSV } From 5a1a296b7c7cb4338ca6fd30f08d789577e4d358 Mon Sep 17 00:00:00 2001 From: Bailard Date: Wed, 10 Apr 2024 10:58:06 -0700 Subject: [PATCH 08/27] Added package prefixes to functions; last commit before radical changes to package structure --- R/chem-qc.R | 176 ++++++++++++++++++++++++++-------------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/R/chem-qc.R b/R/chem-qc.R index 9effcf3..af97616 100644 --- a/R/chem-qc.R +++ b/R/chem-qc.R @@ -21,9 +21,9 @@ qcChemFlags <- function(conn, path.to.data, park, site, field.season, data.sourc chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") flags.list <- chem %>% - filter(Flag %in% c("I", "W", "C")) %>% - select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote) %>% - arrange(SampleFrame, VisitDate, SiteCode) + dplyr::filter(Flag %in% c("I", "W", "C")) %>% + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote) %>% + dplyr::arrange(SampleFrame, VisitDate, SiteCode) return(flags.list) @@ -440,7 +440,7 @@ ChemANC <- function(conn, path.to.data, park, site, field.season, data.source = chem.anc <- rbind(chem, chem.anc.rows) - chem.anc %<>% arrange(SiteCode, VisitDate, Characteristic) %>% + chem.anc %<>% dplyr::arrange(SiteCode, VisitDate, Characteristic) %>% dplyr::relocate(Unit, .before = "LabValue") return(chem.anc) @@ -472,24 +472,24 @@ ChemLakeANCPlot <- function(conn, path.to.data, park, site, field.season, data.s chem.anc <- ChemANC(conn, path.to.data, park, site, field.season, data.source) chem.lake.anc <- chem.anc %>% - filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC") + dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) - chem.lake.anc.plot <- ggplot2::ggplot(chem.lake.anc, aes(x = FieldSeason, y = LabValue, group = Characteristic)) + - geom_point() + - geom_line() + - facet_grid(~SiteShort, scales = "free_y") + - ylab(label = "Acid Neutralizing Capacity (ueq/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Lake acid neutralizing capacity") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - geom_hline(yintercept = c(20, 50, 100, 200), linetype = "dashed", color = "gray 20") + - annotate("text", x = "2012", y = 200, label = "Moderate", vjust = 1) + - annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + - annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + - annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + - scale_x_discrete(breaks = pretty_breaks()) + chem.lake.anc.plot <- ggplot2::ggplot(chem.lake.anc, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic)) + + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Acid Neutralizing Capacity (ueq/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake acid neutralizing capacity") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::geom_hline(yintercept = c(20, 50, 100, 200), linetype = "dashed", color = "gray 20") + + ggplot2::annotate("text", x = "2012", y = 200, label = "Moderate", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) return(chem.lake.anc.plot) @@ -519,24 +519,24 @@ ChemStreamANCPlot <- function(conn, path.to.data, park, site, field.season, data chem.anc <- ChemANC(conn, path.to.data, park, site, field.season, data.source) chem.stream.anc <- chem.anc %>% - filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC") + dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) - chem.stream.anc.plot <- ggplot2::ggplot(chem.stream.anc, aes(x = FieldSeason, y = LabValue, group = Characteristic)) + - geom_point() + - geom_line() + - facet_grid(~SiteShort, scales = "free_y") + - ylab(label = "Acid Neutralizing Capacity (ueq/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Lake acid neutralizing capacity") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - geom_hline(yintercept = c(20, 50, 100, 200), linetype = "dashed", color = "gray 20") + - annotate("text", x = "2012", y = 200, label = "Moderate", vjust = 1) + - annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + - annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + - annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + - scale_x_discrete(breaks = pretty_breaks()) + chem.stream.anc.plot <- ggplot2::ggplot(chem.stream.anc, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic)) + + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Acid Neutralizing Capacity (ueq/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake acid neutralizing capacity") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::geom_hline(yintercept = c(20, 50, 100, 200), linetype = "dashed", color = "gray 20") + + ggplot2::annotate("text", x = "2012", y = 200, label = "Moderate", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + + ggplot2::annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) return(chem.stream.anc.plot) @@ -561,20 +561,20 @@ ChemLakeNutrientPlot <- function(conn, path.to.data, park, site, field.season, d lake.nut$Characteristic_f = factor(lake.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) lake.nut.plot <- ggplot2::ggplot(lake.nut, - aes(x = FieldSeason, + ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_point() + - geom_line() + - facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Lake nutrient concentrations") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake nutrient concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) return(lake.nut.plot) @@ -605,20 +605,20 @@ ChemLakeNutrientBarPlot <- function(conn, path.to.data, park, site, field.season lake.nut.bar %<>% dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) %>% filter(Characteristic != "DOC") - lake.nut.bar.plot <- ggplot2::ggplot(lake.nut.bar, aes(x = FieldSeason, + lake.nut.bar.plot <- ggplot2::ggplot(lake.nut.bar, ggplot2::aes(x = FieldSeason, y = LabValue, fill = Characteristic_f, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_bar(stat = "identity", position = "identity", color = "white") + - facet_grid(Nutrient_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90), legend.position = "bottom") + - labs(title = "Lake nutrient concentrations", fill = "Nutrient") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + - scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) + ggplot2::geom_bar(stat = "identity", position = "identity", color = "white") + + ggplot2::facet_grid(Nutrient_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") + + ggplot2::labs(title = "Lake nutrient concentrations", fill = "Nutrient") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) return(lake.nut.bar.plot) @@ -643,20 +643,20 @@ ChemLakeIonPlot <- function(conn, path.to.data, park, site, field.season, data.s lake.ion$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) - lake.ion.plot <- ggplot2::ggplot(lake.ion, aes(x = FieldSeason, + lake.ion.plot <- ggplot2::ggplot(lake.ion, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_point() + - geom_line() + - facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Lake ion concentrations") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake ion concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2:: scale_x_discrete(breaks = scales::pretty_breaks()) return(lake.ion.plot) @@ -680,20 +680,20 @@ ChemStreamNutrientPlot <- function(conn, path.to.data, park, site, field.season, stream.nut$Characteristic_f = factor(stream.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) - stream.nut.plot <- ggplot2::ggplot(stream.nut, aes(x = FieldSeason, + stream.nut.plot <- ggplot2::ggplot(stream.nut, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_point() + - geom_line() + - facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Stream nutrient concentrations") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Stream nutrient concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) return(stream.nut.plot) @@ -723,20 +723,20 @@ ChemStreamNutrientBarPlot <- function(conn, path.to.data, park, site, field.seas stream.nut.bar %<>% dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) %>% filter(Characteristic != "DOC") - stream.nut.bar.plot <- ggplot2::ggplot(stream.nut.bar, aes(x = FieldSeason, + stream.nut.bar.plot <- ggplot2::ggplot(stream.nut.bar, ggplot2::aes(x = FieldSeason, y = LabValue, fill = Characteristic_f, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_bar(stat = "identity", position = "identity", color = "white") + - facet_grid(Nutrient_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90), legend.position = "bottom") + - labs(title = "Stream nutrient concentrations", fill = "Nutrient") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + - scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) + ggplot2::geom_bar(stat = "identity", position = "identity", color = "white") + + ggplot2::facet_grid(Nutrient_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") + + ggplot2::labs(title = "Stream nutrient concentrations", fill = "Nutrient") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) return(stream.nut.bar.plot) @@ -760,20 +760,20 @@ ChemStreamIonPlot <- function(conn, path.to.data, park, site, field.season, data stream.ion$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) - stream.ion.plot <- ggplot2::ggplot(stream.ion, aes(x = FieldSeason, + stream.ion.plot <- ggplot2::ggplot(stream.ion, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic, text = paste0("Field Season: ", FieldSeason, "
", "Lab Value: ", LabValue, "
", "Parameter: ", Characteristic_f))) + - geom_point() + - geom_line() + - facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ylab(label = "Concentration (mg/L)") + - theme(axis.text.x = element_text(angle = 90)) + - labs(title = "Stream ion concentrations") + - scale_y_continuous(breaks = pretty_breaks(), limits = c(0, NA)) + - scale_x_discrete(breaks = pretty_breaks()) + ggplot2::geom_point() + + ggplot2::geom_line() + + ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Stream ion concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) return(stream.ion.plot) From 35b08b3edcaa7e5773e4cf74b1e8a56dd5282329 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 12 Apr 2024 19:09:46 -0700 Subject: [PATCH 09/27] Created LoadStreamsAndLakes, ReadAGOL, ReadSqlDatabase, ReadAquarius, and other helper functions. Substantially changed ReadAndFilterData function. --- NAMESPACE | 1 - R/utils.R | 563 ++++++++++++++---- man/ReadAndFilterData.Rd | 22 +- ...ReadAquarius.Rd => ReadAquariusStreams.Rd} | 6 +- 4 files changed, 457 insertions(+), 135 deletions(-) rename man/{ReadAquarius.Rd => ReadAquariusStreams.Rd} (89%) diff --git a/NAMESPACE b/NAMESPACE index b4be1fb..98ef838 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,7 +25,6 @@ export(GetRawData) export(GetSiteName) export(LakeSurfaceElevation) export(LakeWqMedian) -export(OpenDatabaseConnection) export(PlotBenchmarkElevation) export(PlotLakeSurfaceElevation) export(SaveDataToCsv) diff --git a/R/utils.R b/R/utils.R index de99606..c667af9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,38 @@ +#' @importFrom magrittr %>% %<>% + +pkg_globals <- new.env(parent = emptyenv()) + +# Load data from global package environment +get_data <- function(data.name) { + if (!missing(data.name)) { + if (!(data.name %in% c(names(GetColSpec()), names(GetAGOLColSpec()), names(GetAquariusColSpec())))) { + stop("Invalid data table name. Use names(streamsandlakes:::GetColSpec()) to see valid options for data.name.") + } + tryCatch({data <- get(data.name, pkg_globals)}, + error = function(e) { + if (grepl(".*object.* not found.*", e$message, ignore.case = TRUE)) { + stop(paste0("Could not find data. Did you remember to call LoadStreamsAndLakes?\n\tOriginal error: ", e$message)) + } + else {e} + }) + } else { + tryCatch({ + data <- lapply(c(names(GetColSpec()), names(GetAGOLColSpec()), names(GetAquariusColSpec())), get, pkg_globals) + names(data) <- c(names(GetColSpec()), names(GetAGOLColSpec()), names(GetAquariusColSpec())) + }, + error = function(e) { + if (grepl(".*object.* not found.*", e$message, ignore.case = TRUE)) { + stop(paste0("Could not find data. Did you remember to call LoadStreamsAndLakes?\n\tOriginal error: ", e$message)) + } + else {e} + } + ) + + } + + return(data) +} + #' Open a Connection to the MOJN Streams and Lakes Database #' #' @param use.mojn.default Connect to the live MOJN Streams and Lakes database? MOJN staff should use this option. Defaults to \code{TRUE}. @@ -5,7 +40,6 @@ #' @param ... Additional arguments to \code{\link[pool]{dbPool}}. Ignored if \code{use.mojn.default} is \code{TRUE}. #' #' @return A database connection pool object -#' @export #' #' @importFrom magrittr %>% %<>% #' @importFrom stats median @@ -220,40 +254,85 @@ GetColSpec <- function() { return(col.spec) } +GetAGOLColSpec <- function() { + col.spec <- list( + BMIMetrics = readr::cols( + SampleID = readr::col_integer(), + CollectionDate = readr::col_date(), + Value = readr::col_double(), + .default = readr::col_character() + ), + BMISpecies = readr::cols( + SampleID = readr::col_integer(), + CollectionDate = readr::col_date(), + SplitCount = readr::col_integer(), + LabCount = readr::col_double(), + BigRareCount = readr::col_integer(), + Sample_ID = readr::col_double(), + .default = readr::col_character() + ), + BMIVisit = readr::cols( + SampleID = readr::col_integer(), + NAMC_Latitude = readr::col_double(), + NAMC_Longitude = readr::col_double(), + Customer_Latitude = readr::col_double(), + Customer_Longitude = readr::col_double(), + CollectionDate = readr::col_date(), + Area = readr::col_double(), + FieldSplit = readr::col_double(), + LabSplit = readr::col_double(), + SplitCount = readr::col_integer(), + .default = readr::col_character() + ) + ) + + return(col.spec) +} + #' Get column specifications for Aquarius data that have been written to csv. #' #' @return A list of column specifications for each csv of Aquarius data. #' GetAquariusColSpec <- function() { - col.spec.aq <- list( - TimeseriesDO = readr::cols( + col.spec <- list( + TimeseriesDOmgl = readr::cols( DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), - DissolvedOxygen_mg_per_L = readr::col_double(), + Value = readr::col_double(), .default = readr::col_character() ), - TimeseriesDOSat = readr::cols( + TimeseriesDOpct = readr::cols( DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), - DissolvedOxygen_percent = readr::col_double(), + Value = readr::col_double(), .default = readr::col_character() ), TimeseriespH = readr::cols( DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), - pH = readr::col_double(), + Value = readr::col_double(), .default = readr::col_character() ), TimeseriesSpCond = readr::cols( DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), - SpecificConductance_microS_per_cm = readr::col_double(), + Value = readr::col_double(), .default = readr::col_character() ), TimeseriesTemperature = readr::cols( DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), - WaterTemperature_C = readr::col_double(), + Value = readr::col_double(), + .default = readr::col_character() + ), + TimeseriesDischarge = readr::cols( + DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), + Value = readr::col_double(), + .default = readr::col_character() + ), + TimeseriesWaterLevel = readr::cols( + DateTime = readr::col_datetime("%y-%m-%d %H:%M:%S %z"), + Value = readr::col_double(), .default = readr::col_character() ) ) - return(col.spec.aq) + return(col.spec) } #' Read Streams and Lakes data from Aquarius @@ -265,17 +344,85 @@ GetAquariusColSpec <- function() { #' #' @details \code{data.name} options are: TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature #' -ReadAquarius <- function(conn, data.name) { +ReadAquariusStreams <- function() { + conn <- OpenDatabaseConnection() + if (!isS4(conn$aquarius)) { stop("Aquarius connection does not exist.") } timeseries <- conn$aquarius + data <- list() aq_data <- tibble::tibble() sites <- c("GRBA_S_BAKR1", "GRBA_S_LHMN1", "GRBA_S_SNKE1", "GRBA_S_SNKE2", "GRBA_S_STRW1") identifiers <- tibble::tibble(data_name = c("TimeseriesDO", "TimeseriesDOSat", "TimeseriespH", "TimeseriesSpCond", "TimeseriesTemperature", "TimeseriesDischarge"), identifier = c("O2 (Dis).Cumulative@", "Dis Oxygen Sat.Cumulative@", "pH.Cumulative@", "Sp Cond.Cumulative@", "Water Temp.Cumulative@", "Discharge.Cumulative@"), col_name = c("DissolvedOxygen_mg_per_L", "DissolvedOxygen_percent", "pH", "SpecificConductance_microS_per_cm", "WaterTemperature_C", "Discharge_cfs")) + aq_identifier <- identifiers$identifier + aq_col_name <- identifiers$col_name + +for(name in aq_identifier) { + + for (location in sites) { + site.imp <- timeseries$getTimeSeriesData(paste0(aq_identifier, location)) + + site.data <- site.imp$Points + + site.data %<>% + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) %>% + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) %>% + # dplyr::filter(Approval == "Approved") %>% + dplyr::mutate(SiteCode = location) %>% + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + + site.data$DateTime <- lubridate::ymd_hms(site.data$DateTime, tz = "America/Los_Angeles", quiet = TRUE) + + site.data %<>% + dplyr::mutate(FieldSeason = ifelse(lubridate::month(DateTime) < 10, + lubridate::year(DateTime), + lubridate::year(DateTime) + 1)) %>% + dplyr::select(Park, + SampleFrame, + SiteCode, + FieldSeason, + DateTime, + Value, + Grade, + Approval) + + aq_data <- rbind(aq_data, site.data) %>% + tibble::as_tibble() %>% + dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% + dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v]+", replacement = "; ") %>% + dplyr::mutate_if(is.character, dplyr::na_if, "") + +# list_name <- as.character((identifiers |> dplyr::filter(identifier == aq_identifier))[1,1]) + +# aq_data <- list(aq_data) +# names(aq_data) <- list_name + } + + data <- append(data, list(aq_data)) +} + + names(data) <- identifiers$data_name + + return(data) +} + +ReadAquariusLakes <- function() { + conn <- OpenDatabaseConnection() + + if (!isS4(conn$aquarius)) { + stop("Aquarius connection does not exist.") + } + timeseries <- conn$aquarius + aq_data <- tibble::tibble() + sites <- c("GRBA_L_BAKR0", "GRBA_L_BRWN0", "GRBA_L_DEAD0", "GRBA_L_JHNS0", "GRBA_L_STLL0", "GRBA_L_TRSA0") + identifiers <- tibble::tibble(data_name = c("TimeseriesWaterLevel"), + identifier = c("Water Level.Cumulative@"), + col_name = c("WaterLevel_m")) + aq_identifier <- identifiers[identifiers$data_name == data.name, ]$identifier aq_col_name <- identifiers[identifiers$data_name == data.name, ]$col_name @@ -284,8 +431,6 @@ ReadAquarius <- function(conn, data.name) { site.data <- site.imp$Points - site.data - # site.imp <- fetchaquarius::getTimeSeries(paste0(aq_identifier, location)) # site.values <- site.imp$Points %>% dplyr::rename(NumericValue1 = Value) @@ -295,7 +440,7 @@ ReadAquarius <- function(conn, data.name) { site.data %<>% dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) %>% dplyr::rename(!!aq_col_name := NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) %>% - # dplyr::filter(Approval == "Approved") %>% + dplyr::filter(Approval == "Approved") %>% dplyr::mutate(SiteCode = location) %>% dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") @@ -324,6 +469,132 @@ ReadAquarius <- function(conn, data.name) { return(aq_data) } +ReadAquarius <- function() { + conn <- streamsandlakes:::OpenDatabaseConnection() + + if (!isS4(conn$aquarius)) { + stop("Aquarius connection does not exist.") + } + + timeseries <- conn$aquarius + data <- list() + wt_data <- tibble::tibble() + ph_data <- tibble::tibble() + sc_data <- tibble::tibble() + domgl_data <- tibble::tibble() + dopct_data <- tibble::tibble() + q_data <- tibble::tibble() + wl_data <- tibble::tibble() + + stream <- c("GRBA_S_BAKR1", "GRBA_S_LHMN1", "GRBA_S_SNKE1", "GRBA_S_SNKE2", "GRBA_S_STRW1") + discharge <- c("GRBA_S_BAKR1", "GRBA_S_SNKE1", "GRBA_S_SNKE2", "GRBA_S_STRW1") + lake <- c("GRBA_L_BAKR0", "GRBA_L_BRWN0", "GRBA_L_DEAD0", "GRBA_L_JHNS0", "GRBA_L_STLL0", "GRBA_L_TRSA0") + + + for (location in stream) { + site.imp <- timeseries$getTimeSeriesData(paste0("Water Temp.Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + wt_data <- rbind(wt_data, site.data) + } + + wt_data <- list(wt_data) + names(wt_data) <- "TimeseriesTemperature" + + for (location in stream) { + site.imp <- timeseries$getTimeSeriesData(paste0("pH.Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + ph_data <- rbind(ph_data, site.data) + } + + ph_data <- list(ph_data) + names(ph_data) <- "TimeseriespH" + + for (location in c("GRBA_S_BAKR1", "GRBA_S_STRW1")) { + site.imp <- timeseries$getTimeSeriesData(paste0("Sp Cond.Cumulative@", location)) + site.data <- as.data.frame(site.imp$Points) |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + sc_data <- rbind(sc_data, site.data) + } + + sc_data <- list(sc_data) + names(sc_data) <- "TimeseriesSpCond" + + for (location in stream) { + site.imp <- timeseries$getTimeSeriesData(paste0("O2 (Dis).Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + domgl_data <- rbind(domgl_data, site.data) + } + + domgl_data <- list(domgl_data) + names(domgl_data) <- "TimeseriesDOmgl" + + for (location in stream) { + site.imp <- timeseries$getTimeSeriesData(paste0("Dis Oxygen Sat.Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + dopct_data <- rbind(dopct_data, site.data) + } + + dopct_data <- list(dopct_data) + names(dopct_data) <- "TimeseriesDOpct" + + for (location in discharge) { + site.imp <- timeseries$getTimeSeriesData(paste0("Discharge.Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") + q_data <- rbind(q_data, site.data) + } + + q_data <- list(q_data) + names(q_data) <- "TimeseriesDischarge" + + for (location in lake) { + site.imp <- timeseries$getTimeSeriesData(paste0("Water Level.Cumulative@", location)) + site.data <- site.imp$Points |> + dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) |> + dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) |> + dplyr::mutate(SiteCode = location) |> + dplyr::mutate(Park = "GRBA", SampleFrame = "Lake") + wl_data <- rbind(wl_data, site.data) + } + + wl_data <- list(wl_data) + names(wl_data) <- "TimeseriesWaterLevel" + + data <- c(wt_data, ph_data, sc_data, domgl_data, dopct_data, q_data, wl_data) + + # Tidy up the data + data <- lapply(data, function(df) { + df |> + dplyr::mutate(DateTime = lubridate::ymd_hms(DateTime, tz = "America/Los_Angeles", quiet = TRUE)) |> + dplyr::mutate(FieldSeason = ifelse(lubridate::month(DateTime) < 10, + lubridate::year(DateTime), + lubridate::year(DateTime) + 1)) + }) + + return(data) +} # Custom function that takes a ggplotly figure and its facets as arguments. # The upper x-values for each domain is set programmatically, but you can adjust @@ -386,65 +657,6 @@ fixfacets <- function(figure, facets, domain_offset){ return(fig) } - -ReadAquariusLakes <- function(conn, data.name) { - if (!isS4(conn$aquarius)) { - stop("Aquarius connection does not exist.") - } - timeseries <- conn$aquarius - aq_data <- tibble::tibble() - sites <- c("GRBA_L_BAKR0", "GRBA_L_BRWN0", "GRBA_L_DEAD0", "GRBA_L_JHNS0", "GRBA_L_STLL0", "GRBA_L_TRSA0") - identifiers <- tibble::tibble(data_name = c("TimeseriesWaterLevel"), - identifier = c("Water Level.Cumulative@"), - col_name = c("WaterLevel_m")) - - aq_identifier <- identifiers[identifiers$data_name == data.name, ]$identifier - aq_col_name <- identifiers[identifiers$data_name == data.name, ]$col_name - - for (location in sites) { - site.imp <- timeseries$getTimeSeriesData(paste0(aq_identifier, location)) - - site.data <- site.imp$Points - - # site.imp <- fetchaquarius::getTimeSeries(paste0(aq_identifier, location)) - - # site.values <- site.imp$Points %>% dplyr::rename(NumericValue1 = Value) - # site.grades <- site.imp$Grades %>% dplyr::rename(NumericValue1 = Value) - # site.approvals <- site.imp$Approvals %>% dplyr::select(LevelDescription) - - site.data %<>% - dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) %>% - dplyr::rename(!!aq_col_name := NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) %>% - # dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(SiteCode = location) %>% - dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") - - site.data$DateTime <- lubridate::ymd_hms(site.data$DateTime, tz = "America/Los_Angeles", quiet = TRUE) - - site.data %<>% - dplyr::mutate(FieldSeason = ifelse(lubridate::month(DateTime) < 10, - lubridate::year(DateTime), - lubridate::year(DateTime) + 1)) %>% - dplyr::select(Park, - SampleFrame, - SiteCode, - FieldSeason, - DateTime, - !!aq_col_name, - Grade, - Approval) - - aq_data <- rbind(aq_data, site.data) %>% - tibble::as_tibble() %>% - dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% - dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v]+", replacement = "; ") %>% - dplyr::mutate_if(is.character, dplyr::na_if, "") - } - - return(aq_data) -} - - #' Read Streams and Lakes data from database or .csv #' #' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. @@ -459,59 +671,41 @@ ReadAquariusLakes <- function(conn, data.name) { #' #' @details \code{data.name} options are: Site, Visit, BMI, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature #' -ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data.source = "database", data.name) { - col.spec <- GetColSpec() - col.spec.aq <- GetAquariusColSpec() - col.spec.all <- c(col.spec, col.spec.aq) +ReadAndFilterData <- function(park, site, field.season, data.name) { + filtered.data <- get_data(data.name) - if (!(data.source %in% c("database", "local"))) { - stop("Please choose either 'database' or 'local' for data.source") + if (!missing(field.season)) { + field.season <- as.character(field.season) } - if (data.source == "database" & data.name %in% names(col.spec)) { - filtered.data <- dplyr::tbl(conn$db, dbplyr::in_schema("analysis", data.name)) %>% - dplyr::collect() %>% - dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% - dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v]+", replacement = "; ") %>% - dplyr::mutate_if(is.character, dplyr::na_if, "") - } else if (data.source == "database" & data.name %in% names(col.spec.aq)) { - ## Read Aquarius data - filtered.data <- ReadAquarius(conn, data.name) - } else if (data.source == "local") { - filtered.data <- readr::read_csv(file.path(path.to.data, paste0(data.name, ".csv")), na = "", col_types = col.spec.all[[data.name]], lazy = FALSE) - if(data.name %in% names(col.spec.aq) & "DateTime" %in% names(filtered.data)) { - filtered.data$DateTime <- lubridate::with_tz(filtered.data$DateTime, "America/Los_Angeles") + if (!missing(park)) { + filtered.data %<>% + dplyr::filter(Park %in% park) # Changed to allow filtering of multiple parks + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for the park specified")) } } - if (!missing(park)) { - filtered.data %<>% - dplyr::filter(Park == park) - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for the park specified")) - } - } + if (!missing(site) & nrow(filtered.data) > 0) { + filtered.data %<>% + dplyr::filter(SiteCode == site) - if (!missing(site) & nrow(filtered.data) > 0) { - filtered.data %<>% - dplyr::filter(SiteCode %in% site) - - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for the site specified")) - } + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for the site specified")) } + } - if ("FieldSeason" %in% names(filtered.data)) { - filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) - } + if ("FieldSeason" %in% names(filtered.data)) { + filtered.data %<>% dplyr::mutate(FieldSeason = as.character(FieldSeason)) + } - if (!missing(field.season) & ("FieldSeason" %in% colnames(filtered.data)) & nrow(filtered.data) > 0) { - filtered.data %<>% - dplyr::filter(FieldSeason %in% field.season) - if (nrow(filtered.data) == 0) { - warning(paste0(data.name, ": Data are not available for one or more of the field seasons specified")) - } + if (!missing(field.season) & ("FieldSeason" %in% colnames(filtered.data)) & nrow(filtered.data) > 0) { + filtered.data %<>% + dplyr::filter(FieldSeason %in% field.season) + if (nrow(filtered.data) == 0) { + warning(paste0(data.name, ": Data are not available for one or more of the field seasons specified")) } + } return(filtered.data) } @@ -613,9 +807,10 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = GetRawData <- function(conn, path.to.data, park, site, field.season, data.source = "database") { data.dump <- list() db.names <- names(GetColSpec()) + bmi.names <- names(GetAGOLColSpec()) aq.names <- names(GetAquariusColSpec()) - data.names <- c(db.names, aq.names) + data.names <- c(db.names, bmi.names, aq.names) for (data.name in data.names) { tryCatch(data.dump[[data.name]] <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name), @@ -837,9 +1032,145 @@ fetchAndWrangleBMI <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQ raw_data$data[['BMI_Metadata']] <- NULL raw_data$metadata[['BMI_Metadata']] <- NULL + names(raw_data$data) <- c("BMISpecies", "BMIMetrics", "BMIVisit") + invisible(raw_data) } +fetchandWrangleAGOL <- function() { + # Placeholder until more STLK data beyond BMI are moved from SQL to AGOL +} + +ReadAGOL <- function(...) { + #Placeholder until more STLK data beyond BMI are moved from SQL to AGOL + data <- fetchAndWrangleBMI()$data # Change name of variable to bmi once there are more data + # agol <- fetchAndWrangleAGOL()$data + + # data <- c(bmi, agol) + + return(data) +} + +ReadSqlDatabase <- function(...) { + col.spec <- GetColSpec() + conn <- OpenDatabaseConnection(...) + data <- lapply(names(col.spec), function(data.name){ + df <- dplyr::tbl(conn$db, dbplyr::in_schema("analysis", data.name)) %>% + dplyr::collect() + return(df) + }) + + names(data) <- names(col.spec) + CloseDatabaseConnection(conn) + return(data) +} + +ReadCSV <- function(data_path) { + data_path <- normalizePath(data_path) + col.spec <- GetColSpec() + is_zip <- grepl("\\.zip", data_path, ignore.case = TRUE) + + if(is_zip) { + file_list <- basename(unzip(data_path, list = TRUE)$Name) + } else { + file_list <- list.files(data_path) + } + # Make sure that files in folder are valid CSVs + expected_files <- paste0(names(col.spec), ".csv") + if (!all(expected_files %in% file_list)) { + missing_files <- setdiff(expected_files, file_list) + missing_files <- paste(missing_files, collapse = "\n") + stop(paste0("The folder provided is missing required data. Missing files:\n", missing_files)) + } + + # Read data + if (is_zip) { # Unzip into a temporary directory to read files + temp_dir <- tempdir() + # Use this trycatch so that even if there's an error unzipping or reading, the temp dir will be deleted + tryCatch({ + unzip(data_path, overwrite = TRUE, exdir = temp_dir, junkpaths = TRUE) + data <- lapply(names(col.spec), function(data.name){ + file_path <- file.path(temp_dir, paste0(data.name, ".csv")) + df <- readr::read_csv(file = file_path, col_types = col.spec[[data.name]], locale = readr::locale(encoding = "UTF-8")) + return(df) + }) + }, + finally = unlink(temp_dir, recursive = TRUE) + ) + } else { # Read files from data path + data <- lapply(names(col.spec), function(data.name){ + file_path <- file.path(data_path, paste0(data.name, ".csv")) + df <- readr::read_csv(file = file_path, col_types = col.spec[[data.name]], locale = readr::locale(encoding = "UTF-8")) + return(df) + }) + } + + names(data) <- names(col.spec) + return(data) +} + +LoadStreamsAndLakes <- function(data_path = c("database", "aquarius", + bmi_db = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + calibration_db = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer"), + use_default_sql = TRUE, sql_drv = odbc::odbc(), agol_username = "mojn_data", agol_password = rstudioapi::askForPassword(paste("Please enter the password for AGOL account", agol_username)), ...) { + + # Figure out the format of the data + agol_regex <- "^https:\\/\\/services1\\.arcgis\\.com\\/[^\\\\]+\\/arcgis\\/rest\\/services\\/[^\\\\]+\\/FeatureServer\\/?$" + is_agol <- ifelse(any(grepl(agol_regex, data_path) == TRUE), TRUE, FALSE) + is_db <- ifelse(any(grepl("^database$", data_path, ignore.case = TRUE) == TRUE), TRUE, FALSE) + is_aquarius <- ifelse(any(grepl("^aquarius$", data_path, ignore.case = TRUE) == TRUE), TRUE, FALSE) + if (!is_agol & !is_db) { + # Standardize data path + data_path <- normalizePath(data_path[1], mustWork = TRUE) + } + is_zip <- grepl("\\.zip$", data_path[1], ignore.case = TRUE) && file.exists(data_path[1]) + is_folder <- dir.exists(data_path[1]) + + data <- list() + + if (is_agol) { # Read from AGOL feature layer + agol <- ReadAGOL(...) + data <- append(data, agol) + } + + if(is_aquarius) { # Read from Aquarius + aquarius <- ReadAquarius(...) + data <- append(data, aquarius) + } + + if (is_db) { # Read from SQL Server database + sql <- ReadSqlDatabase(...) + data <- append(data, sql) + } + + if (is_zip | is_folder) { # Read from folder of CSVs (may be zipped) + csv <- ReadCSV(data_path[1]) + data <- append(data, csv) + } + + if (!is_agol & !is_db & !is_zip & !is_folder) { + stop(paste("Data path", data_path[1], "is invalid. See `?LoadStreamsAndLakes` for more information.")) + } + + # Tidy up the data + data <- lapply(data, function(df) { + df %>% + dplyr::mutate_if(is.character, utf8::utf8_encode) %>% + dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% # Trim leading and trailing whitespace + dplyr::mutate_if(is.character, dplyr::na_if, "") %>% # Replace empty strings with NA + dplyr::mutate_if(is.character, dplyr::na_if, "\\\\n") %>% # Replace newlines with NA + dplyr::mutate_if(is.numeric, dplyr::na_if, -9999) %>% # Replace -9999 or -999 with NA + dplyr::mutate_if(is.numeric, dplyr::na_if, -999) %>% + dplyr::mutate_if(is.character, dplyr::na_if, "NA") %>% # Replace "NA" strings with NA + dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v|\\n]+", replacement = "; ") # Replace newlines with semicolons - reading certain newlines into R can cause problems + }) + + # Actually load the data into an environment for the package to use + tbl_names <- names(data) + lapply(tbl_names, function(n) {assign(n, data[[n]], envir = pkg_globals)}) + + invisible(data) +} #' Write BMI data to CSV #' diff --git a/man/ReadAndFilterData.Rd b/man/ReadAndFilterData.Rd index 0df2aab..4e03283 100644 --- a/man/ReadAndFilterData.Rd +++ b/man/ReadAndFilterData.Rd @@ -4,30 +4,22 @@ \alias{ReadAndFilterData} \title{Read Streams and Lakes data from database or .csv} \usage{ -ReadAndFilterData( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - data.name -) +ReadAndFilterData(park, site, field.season, data.name) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{data.name}{The name of the analysis view or the csv file containing the data. E.g. "CalibrationDO", "DischargeVolumetric". See details for full list of data name options.} + +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble of filtered data. diff --git a/man/ReadAquarius.Rd b/man/ReadAquariusStreams.Rd similarity index 89% rename from man/ReadAquarius.Rd rename to man/ReadAquariusStreams.Rd index 39831ef..7ce930b 100644 --- a/man/ReadAquarius.Rd +++ b/man/ReadAquariusStreams.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R -\name{ReadAquarius} -\alias{ReadAquarius} +\name{ReadAquariusStreams} +\alias{ReadAquariusStreams} \title{Read Streams and Lakes data from Aquarius} \usage{ -ReadAquarius(conn, data.name) +ReadAquariusStreams() } \arguments{ \item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} From 3595c06ebd9d7cb5c0ad9bd1bbc2f3a0a4029d0b Mon Sep 17 00:00:00 2001 From: Bailard Date: Wed, 17 Apr 2024 12:36:40 -0700 Subject: [PATCH 10/27] Added Roxygen info to utils functions --- NAMESPACE | 5 +- R/utils.R | 278 +++++++++++++++++++++++------------------------------- 2 files changed, 122 insertions(+), 161 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 98ef838..0aecd89 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,8 +25,11 @@ export(GetRawData) export(GetSiteName) export(LakeSurfaceElevation) export(LakeWqMedian) +export(LoadStreamsAndLakes) export(PlotBenchmarkElevation) export(PlotLakeSurfaceElevation) +export(ReadAndFilterData) +export(ReadCSV) export(SaveDataToCsv) export(StreamWqMedian) export(SurveyPointElevation) @@ -37,7 +40,7 @@ export(WqPlotPHDepthProfile) export(WqPlotSpCondDepthProfile) export(WqPlotTemperatureDepthProfile) export(expect_dataframe_equal) -export(fetchAndWrangleBMI) +export(fetchAndWrangleAGOL) export(getMDLLookup) export(qcBMIDiscrepancies) export(qcBenchmarkElevation) diff --git a/R/utils.R b/R/utils.R index c667af9..3b6fc78 100644 --- a/R/utils.R +++ b/R/utils.R @@ -33,7 +33,7 @@ get_data <- function(data.name) { return(data) } -#' Open a Connection to the MOJN Streams and Lakes Database +#' Open a connection to the Streams and Lakes Database #' #' @param use.mojn.default Connect to the live MOJN Streams and Lakes database? MOJN staff should use this option. Defaults to \code{TRUE}. #' @param drv DBI driver to use. Defaults to \code{odbc::odbc()}. @@ -93,9 +93,9 @@ CloseDatabaseConnection <- function(conn) { } } -#' Get column specifications +#' Get column specifications for SQL database #' -#' @return A list of column specifications for each table of data. +#' @return A list of column specifications for each table of SQL data. #' GetColSpec <- function() { col.spec <- list( @@ -254,6 +254,10 @@ GetColSpec <- function() { return(col.spec) } +#' Get column specifications for AGOL database +#' +#' @return A list of column specifications for each table of Aquarius data. +#' GetAGOLColSpec <- function() { col.spec <- list( BMIMetrics = readr::cols( @@ -283,15 +287,44 @@ GetAGOLColSpec <- function() { LabSplit = readr::col_double(), SplitCount = readr::col_integer(), .default = readr::col_character() + ), + CalibrationDO = readr::cols( + VisitDate = readr::col_date(), + CalibrationDate = readr::col_date(), + BarometricPressure_mmHg = readr::col_double(), + PreCalibrationReading_percent = readr::col_double(), + PreCalibrationTemperature_C = readr::col_double(), + PostCalibrationReading_percent = readr::col_double(), + PostCalibrationTemperature_C = readr::col_double(), + .default = readr::col_character() + ), + CalibrationpH = readr::cols( + VisitDate = readr::col_date(), + CalibrationDate = readr::col_date(), + StandardValue_pH = readr::col_double(), + TemperatureCorrectedStd_pH = readr::col_double(), + PreCalibrationReading_pH = readr::col_double(), + PreCalibrationTemperature_C = readr::col_double(), + PostCalibrationReading_pH = readr::col_double(), + PostCalibrationTemperature_C = readr::col_double(), + .default = readr::col_character() + ), + CalibrationSpCond = readr::cols( + VisitDate = readr::col_date(), + CalibrationDate = readr::col_date(), + StandardValue_microS_per_cm = readr::col_double(), + PreCalibrationReading_microS_per_cm = readr::col_double(), + PostCalibrationReading_microS_per_cm = readr::col_double(), + .default = readr::col_character() ) ) return(col.spec) } -#' Get column specifications for Aquarius data that have been written to csv. +#' Get column specifications for Aquarius database #' -#' @return A list of column specifications for each csv of Aquarius data. +#' @return A list of column specifications for each table of Aquarius data. #' GetAquariusColSpec <- function() { col.spec <- list( @@ -335,142 +368,12 @@ GetAquariusColSpec <- function() { return(col.spec) } -#' Read Streams and Lakes data from Aquarius +#' Read data from the Aquarius database #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param data.name The name of the data table. E.g. "TimeseriesDO". See details for full list of data name options. -#' -#' @return A tibble of Aquarius data, wrangled and formatted. -#' -#' @details \code{data.name} options are: TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature +#' @return A list of tibbles #' -ReadAquariusStreams <- function() { - conn <- OpenDatabaseConnection() - - if (!isS4(conn$aquarius)) { - stop("Aquarius connection does not exist.") - } - timeseries <- conn$aquarius - data <- list() - aq_data <- tibble::tibble() - sites <- c("GRBA_S_BAKR1", "GRBA_S_LHMN1", "GRBA_S_SNKE1", "GRBA_S_SNKE2", "GRBA_S_STRW1") - identifiers <- tibble::tibble(data_name = c("TimeseriesDO", "TimeseriesDOSat", "TimeseriespH", "TimeseriesSpCond", "TimeseriesTemperature", "TimeseriesDischarge"), - identifier = c("O2 (Dis).Cumulative@", "Dis Oxygen Sat.Cumulative@", "pH.Cumulative@", "Sp Cond.Cumulative@", "Water Temp.Cumulative@", "Discharge.Cumulative@"), - col_name = c("DissolvedOxygen_mg_per_L", "DissolvedOxygen_percent", "pH", "SpecificConductance_microS_per_cm", "WaterTemperature_C", "Discharge_cfs")) - - aq_identifier <- identifiers$identifier - aq_col_name <- identifiers$col_name - -for(name in aq_identifier) { - - for (location in sites) { - site.imp <- timeseries$getTimeSeriesData(paste0(aq_identifier, location)) - - site.data <- site.imp$Points - - site.data %<>% - dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) %>% - dplyr::rename(Value = NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) %>% - # dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(SiteCode = location) %>% - dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") - - site.data$DateTime <- lubridate::ymd_hms(site.data$DateTime, tz = "America/Los_Angeles", quiet = TRUE) - - site.data %<>% - dplyr::mutate(FieldSeason = ifelse(lubridate::month(DateTime) < 10, - lubridate::year(DateTime), - lubridate::year(DateTime) + 1)) %>% - dplyr::select(Park, - SampleFrame, - SiteCode, - FieldSeason, - DateTime, - Value, - Grade, - Approval) - - aq_data <- rbind(aq_data, site.data) %>% - tibble::as_tibble() %>% - dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% - dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v]+", replacement = "; ") %>% - dplyr::mutate_if(is.character, dplyr::na_if, "") - -# list_name <- as.character((identifiers |> dplyr::filter(identifier == aq_identifier))[1,1]) - -# aq_data <- list(aq_data) -# names(aq_data) <- list_name - } - - data <- append(data, list(aq_data)) -} - - names(data) <- identifiers$data_name - - return(data) -} - -ReadAquariusLakes <- function() { - conn <- OpenDatabaseConnection() - - if (!isS4(conn$aquarius)) { - stop("Aquarius connection does not exist.") - } - timeseries <- conn$aquarius - aq_data <- tibble::tibble() - sites <- c("GRBA_L_BAKR0", "GRBA_L_BRWN0", "GRBA_L_DEAD0", "GRBA_L_JHNS0", "GRBA_L_STLL0", "GRBA_L_TRSA0") - identifiers <- tibble::tibble(data_name = c("TimeseriesWaterLevel"), - identifier = c("Water Level.Cumulative@"), - col_name = c("WaterLevel_m")) - - aq_identifier <- identifiers[identifiers$data_name == data.name, ]$identifier - aq_col_name <- identifiers[identifiers$data_name == data.name, ]$col_name - - for (location in sites) { - site.imp <- timeseries$getTimeSeriesData(paste0(aq_identifier, location)) - - site.data <- site.imp$Points - - # site.imp <- fetchaquarius::getTimeSeries(paste0(aq_identifier, location)) - - # site.values <- site.imp$Points %>% dplyr::rename(NumericValue1 = Value) - # site.grades <- site.imp$Grades %>% dplyr::rename(NumericValue1 = Value) - # site.approvals <- site.imp$Approvals %>% dplyr::select(LevelDescription) - - site.data %<>% - dplyr::select(Timestamp, NumericValue1, GradeName1, ApprovalName1) %>% - dplyr::rename(!!aq_col_name := NumericValue1, Grade = GradeName1, Approval = ApprovalName1, DateTime = Timestamp) %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(SiteCode = location) %>% - dplyr::mutate(Park = "GRBA", SampleFrame = "Stream") - - site.data$DateTime <- lubridate::ymd_hms(site.data$DateTime, tz = "America/Los_Angeles", quiet = TRUE) - - site.data %<>% - dplyr::mutate(FieldSeason = ifelse(lubridate::month(DateTime) < 10, - lubridate::year(DateTime), - lubridate::year(DateTime) + 1)) %>% - dplyr::select(Park, - SampleFrame, - SiteCode, - FieldSeason, - DateTime, - !!aq_col_name, - Grade, - Approval) - - aq_data <- rbind(aq_data, site.data) %>% - tibble::as_tibble() %>% - dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% - dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v]+", replacement = "; ") %>% - dplyr::mutate_if(is.character, dplyr::na_if, "") - } - - return(aq_data) -} - -ReadAquarius <- function() { - conn <- streamsandlakes:::OpenDatabaseConnection() +ReadAquarius <- function(...) { + conn <- OpenDatabaseConnection(...) if (!isS4(conn$aquarius)) { stop("Aquarius connection does not exist.") @@ -593,6 +496,7 @@ ReadAquarius <- function() { lubridate::year(DateTime) + 1)) }) + CloseDatabaseConnection(conn) return(data) } @@ -659,17 +563,15 @@ fixfacets <- function(figure, facets, domain_offset){ #' Read Streams and Lakes data from database or .csv #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' @param data.name The name of the analysis view or the csv file containing the data. E.g. "CalibrationDO", "DischargeVolumetric". See details for full list of data name options. #' #' @return A tibble of filtered data. +#' @export #' -#' @details \code{data.name} options are: Site, Visit, BMI, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature +#' @details \code{data.name} options are: Site, Visit, BMIVisit, BMIMetrics, BMISpecies, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, CalibrationDO, CalibrationpH, CalibrationSpCond, TimeseriesDOmgl, TimeseriesDOpct, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature, TimeseriesDischarge, TimeseriesWaterLevel #' ReadAndFilterData <- function(park, site, field.season, data.name) { filtered.data <- get_data(data.name) @@ -751,20 +653,20 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = # Write each analysis view in the database to csv for (view.name in analysis.views) { - df <- ReadAndFilterData(conn, data.source = "database", data.name = view.name) + df <- ReadAndFilterData(data.name = view.name) readr::write_csv(df, file.path(dest.folder, paste0(view.name, ".csv")), na = "", append = FALSE, col_names = TRUE) } #write calculated summary tables to csv if (calculated) { - df <- StreamWqMedian(conn) + df <- StreamWqMedian() readr::write_csv(df, file.path(dest.folder, paste0("WQStreamXSection_CALCULATED", ".csv")), na = "", append = FALSE, col_names = TRUE) - df <- LakeWqMedian(conn) + df <- LakeWqMedian() readr::write_csv(df, file.path(dest.folder, paste0("WaterQuality_CALCULATED", ".csv")), na = "", append = FALSE, col_names = TRUE) - df <- LakeSurfaceElevation(conn) + df <- LakeSurfaceElevation() readr::write_csv(df, file.path(dest.folder, paste0("LakeLevel_CALCULATED", ".csv")), na = "", append = FALSE, col_names = TRUE) } @@ -774,7 +676,7 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = for (aq.name in aq.data) { tryCatch( { - df <- ReadAquarius(conn, aq.name) + df <- ReadAquarius(aq.name) # Include time zone in dates if("DateTime" %in% names(df)) { df$DateTime <- format(df$DateTime, "%y-%m-%d %H:%M:%S %z") @@ -1022,28 +924,45 @@ expect_dataframe_equal <- function(result, expected, ignore_col_order = FALSE, i #' #' @return A list of data frames and metadata #' @export -fetchAndWrangleBMI <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", - agol_username = "mojn_data") { +fetchAndWrangleAGOL <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + calibration_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer", + agol_username = "mojn_data", + show_col_types = FALSE) { # Import BMI database - raw_data <- fetchagol::fetchRawData(bmi_url, agol_username) - raw_data <- fetchagol::cleanData(raw_data) + raw_bmi <- fetchagol::fetchRawData(bmi_url, agol_username) + raw_bmi <- fetchagol::cleanData(raw_bmi) # Remove unwanted data and metadata - raw_data$data[['BMI_Metadata']] <- NULL - raw_data$metadata[['BMI_Metadata']] <- NULL + raw_bmi$data[['BMI_Metadata']] <- NULL + raw_bmi$metadata[['BMI_Metadata']] <- NULL - names(raw_data$data) <- c("BMISpecies", "BMIMetrics", "BMIVisit") + names(raw_bmi$data) <- c("BMISpecies", "BMIMetrics", "BMIVisit") - invisible(raw_data) -} + raw_bmi$data <- lapply(raw_bmi$data, function(df) { + df |> + dplyr::filter(SiteCode %in% c("GRBA_S_BAKR2", "GRBA_S_BAKR3", "GRBA_S_LHMN2", "GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1", "GRBA_S_SFBW1", "GRBA_S_SHNG1", "GRBA_S_SNKE4", "GRBA_S_STRW2")) + # dplyr::mutate(CollectionDate = as.Date("CollectionDateText", tz = "America/Los_Angeles")) + }) -fetchandWrangleAGOL <- function() { - # Placeholder until more STLK data beyond BMI are moved from SQL to AGOL + # Import WQ calibration database + raw_agol <- fetchagol::fetchRawData(calibration_url, agol_username) + raw_agol <- fetchagol::cleanData(raw_agol) + + # Combine data frames from different AGOL feature layers into one list + raw_data <- c(raw_bmi$data, raw_agol$data) + + invisible(raw_data) } +#' Read data from the Streams and Lakes AGOL feature layer +#' +#' @param ... +#' +#' @return A list of tibbles +#' ReadAGOL <- function(...) { #Placeholder until more STLK data beyond BMI are moved from SQL to AGOL - data <- fetchAndWrangleBMI()$data # Change name of variable to bmi once there are more data + data <- fetchAndWrangleAGOL()$data # Change name of variable to bmi once there are more data # agol <- fetchAndWrangleAGOL()$data # data <- c(bmi, agol) @@ -1051,6 +970,12 @@ ReadAGOL <- function(...) { return(data) } +#' Read data from the Streams and Lakes SQL database +#' +#' @param ... Optional arguments to be passed to `OpenDatabaseConnection()` +#' +#' @return A list of tibbles +#' ReadSqlDatabase <- function(...) { col.spec <- GetColSpec() conn <- OpenDatabaseConnection(...) @@ -1065,6 +990,14 @@ ReadSqlDatabase <- function(...) { return(data) } +#' Title +#' +#' @param data_path +#' +#' @return +#' @export +#' +#' @examples ReadCSV <- function(data_path) { data_path <- normalizePath(data_path) col.spec <- GetColSpec() @@ -1109,6 +1042,31 @@ ReadCSV <- function(data_path) { return(data) } +#' Load raw data into package environment +#' @description Run this function before you do anything else. +#' +#' @param data_path A path or URL to the data. Accepted inputs: +#' * 2 URLs to the AGOL feature services containing the data (bmi_db and calibration_db) +#' * a folder containing the data in csv format +#' * a .zip file containing the data in csv format +#' * `"database"` (connect to the SQL server database) +#' * `"aquarius"` (connect to the Aquarius database) +#' @param use_default_sql Use default SQL database? Ignored if `data_path != "database"`. +#' @param sql_drv Driver to use to connect to database. Ignored if `data_path != "database"`. +#' @param agol_username +#' @param agol_password +#' @param ... +#' +#' @return Invisibly return a list containing all raw data +#' @export +#' +#' @examples +#' \dontrun{ +#' LoadStreamsAndLakes() # Read from all sources (e.g., AGOL, SQL, Aquarius, CSVs) +#' LoadStreamsAndLakes("aquarius") # Read from Aquarius database only +#' LoadStreamsAndLakes("path/to/csv/folder") # Read from folder of CSVs +#' LoadStreamsAndLakes("path/to/zipped/csvs.zip") # Read from zip file of CSVs +#' } LoadStreamsAndLakes <- function(data_path = c("database", "aquarius", bmi_db = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", calibration_db = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer"), From 33a435ffcd93d26deb769d8493ef24a0bbe7945f Mon Sep 17 00:00:00 2001 From: Bailard Date: Wed, 17 Apr 2024 12:39:29 -0700 Subject: [PATCH 11/27] Updated all function arguments to accommodate LoadStreamsAndLakes --- R/bmi-qc.R | 46 +++--- R/calculations.R | 18 +-- R/chem-qc.R | 72 ++++----- R/clarity-qc.R | 30 ++-- R/efficiency-qc.R | 144 +++++++++--------- R/levels-qc.R | 48 +++--- R/wq-qc.R | 62 ++++---- man/BMIDiversityMetricsPlot.Rd | 17 +-- man/BMIFormatted.Rd | 17 +-- man/BMIFunctionalMetricsPlot.Rd | 17 +-- man/BMIGeneralMetricsPlot.Rd | 17 +-- man/BMILong.Rd | 10 +- man/BMITaxonomicMetricsPlot.Rd | 17 +-- man/BMIToleranceMetricsPlot.Rd | 17 +-- man/ChannelCharacteristics.Rd | 17 +-- man/ChannelFLow.Rd | 17 +-- man/ChannelSubstrate.Rd | 17 +-- man/ChemANC.Rd | 10 +- man/ChemLakeANCPlot.Rd | 17 +-- man/ChemLakeIonPlot.Rd | 15 +- man/ChemLakeNutrientBarPlot.Rd | 15 +- man/ChemLakeNutrientPlot.Rd | 15 +- man/ChemStreamANCPlot.Rd | 17 +-- man/ChemStreamIonPlot.Rd | 15 +- man/ChemStreamNutrientBarPlot.Rd | 15 +- man/ChemStreamNutrientPlot.Rd | 15 +- man/GetAGOLColSpec.Rd | 14 ++ man/GetAquariusColSpec.Rd | 6 +- man/GetColSpec.Rd | 6 +- man/LakeSurfaceElevation.Rd | 15 +- man/LakeWqMedian.Rd | 17 +-- man/LoadStreamsAndLakes.Rd | 50 ++++++ man/OpenDatabaseConnection.Rd | 4 +- man/PlotBenchmarkElevation.Rd | 9 -- man/PlotLakeSurfaceElevation.Rd | 9 -- man/ReadAGOL.Rd | 17 +++ man/ReadAndFilterData.Rd | 8 +- man/ReadAquarius.Rd | 14 ++ man/ReadAquariusStreams.Rd | 22 --- man/ReadCSV.Rd | 14 ++ man/ReadSqlDatabase.Rd | 17 +++ man/StreamWqMedian.Rd | 17 +-- man/SurveyPointElevation.Rd | 15 +- man/WqDailyMean.Rd | 17 +-- man/WqDailyMeanLong.Rd | 15 +- man/WqPlotDODepthProfile.Rd | 13 +- man/WqPlotDepthProfile.Rd | 11 +- man/WqPlotPHDepthProfile.Rd | 13 +- man/WqPlotSpCondDepthProfile.Rd | 13 +- man/WqPlotTemperatureDepthProfile.Rd | 11 +- ...ndWrangleBMI.Rd => fetchAndWrangleAGOL.Rd} | 11 +- man/qcBMIDiscrepancies.Rd | 17 +-- man/qcBenchmarkElevation.Rd | 16 +- man/qcChemFieldBlanks.Rd | 17 +-- man/qcChemFieldDupes.Rd | 17 +-- man/qcChemFlags.Rd | 17 +-- man/qcChemLabDupes.Rd | 17 +-- man/qcChemMDL.Rd | 17 +-- man/qcChemML.Rd | 17 +-- man/qcChemNO3NO2.Rd | 17 +-- man/qcChemTDN.Rd | 17 +-- man/qcChemTDP.Rd | 17 +-- man/qcClosureErrorDiscrepancies.Rd | 17 +-- man/qcDPLCheck.Rd | 15 +- man/qcElevationDiscrepancies.Rd | 17 +-- man/qcLakeDryMeasurementsExist.Rd | 17 +-- man/qcLakeNotDryMeasurementsMissing.Rd | 17 +-- man/qcLakeWqCleaned.Rd | 17 +-- man/qcLakeWqFlags.Rd | 17 +-- man/qcLakeWqSanity.Rd | 17 +-- man/qcNoAnnualVisit.Rd | 15 +- man/qcSecchiDepthMissing.Rd | 17 +-- man/qcSecchiGTDepth.Rd | 17 +-- man/qcStreamWqCleaned.Rd | 17 +-- man/qcStreamWqFlags.Rd | 17 +-- man/qcStreamWqSanity.Rd | 17 +-- man/qcStringSurveyElevations.Rd | 16 +- man/qcStringSurveyHeights.Rd | 16 +- man/qcWqCleaned.Rd | 22 +-- man/qcWqCompleteness.Rd | 17 +-- man/qcWqCompletenessPlot.Rd | 17 +-- man/qcWqFlags.Rd | 22 +-- man/qcWqGrades.Rd | 17 +-- man/qcWqGradesLong.Rd | 17 +-- man/qcWqGradesPlot.Rd | 17 +-- man/qcWqSanity.Rd | 22 +-- 86 files changed, 621 insertions(+), 1057 deletions(-) create mode 100644 man/GetAGOLColSpec.Rd create mode 100644 man/LoadStreamsAndLakes.Rd create mode 100644 man/ReadAGOL.Rd create mode 100644 man/ReadAquarius.Rd delete mode 100644 man/ReadAquariusStreams.Rd create mode 100644 man/ReadCSV.Rd create mode 100644 man/ReadSqlDatabase.Rd rename man/{fetchAndWrangleBMI.Rd => fetchAndWrangleAGOL.Rd} (66%) diff --git a/R/bmi-qc.R b/R/bmi-qc.R index 461c69f..f10da38 100644 --- a/R/bmi-qc.R +++ b/R/bmi-qc.R @@ -18,8 +18,8 @@ #' bmi_long_bakr_2015 <- BMILong(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") #' CloseDatabaseConnection(c) #' } -BMILong <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "BMI") +BMILong <- function(park, site, field.season) { + bmi <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMI") # Fix column names (will eventually be fixed in db and we can get rid of this code) if ("PlecopteraTaxa" %in% names(bmi)) { bmi %<>% dplyr::rename(PlecopteraTaxaCount = PlecopteraTaxa) @@ -104,8 +104,8 @@ BMILong <- function(conn, path.to.data, park, site, field.season, data.source = #' bmi_issues_bakr_2015 <- qcBMIDiscrepancies(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") # Look at issues for Baker Creek sites in 2015 #' CloseDatabaseConnection(c) #' } -qcBMIDiscrepancies <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi_issues <- BMILong(conn, path.to.data, park, site, field.season, data.source) %>% +qcBMIDiscrepancies <- function(park, site, field.season) { + bmi_issues <- BMILong(park = park, site = site, field.season = field.season) %>% dplyr::select(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupRichness, TaxaGroupDensity, LabNotes) %>% dplyr::filter((TaxaGroupRichness == 0 & TaxaGroupDensity > 0) | (TaxaGroupDensity == 0 & TaxaGroupRichness > 0)) @@ -132,9 +132,9 @@ qcBMIDiscrepancies <- function(conn, path.to.data, park, site, field.season, dat #' channel_STRW2_2016 <- ChannelCharacteristics(conn, site = "GRBA_S_STRW2", field.season = "2016") #' CloseDatabaseConnection(conn) #' } -ChannelCharacteristics <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - data <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Channel") - visit <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Visit") +ChannelCharacteristics <- function(park, site, field.season) { + data <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Channel") + visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") channel_characteristics <- dplyr::left_join(data, visit[, c("Park", "SiteShort", "SiteCode", "SiteName", "FieldSeason", "VisitDate", "VisitType")], by = c("Park", "SiteShort", "SiteCode", "SiteName", "FieldSeason", "VisitDate")) %>% dplyr::filter(VisitType == "Primary") %>% @@ -163,8 +163,8 @@ ChannelCharacteristics <- function(conn, path.to.data, park, site, field.season, #' channel_flow_STRW2_2016 <- ChannelFlow(conn, site = "GRBA_S_STRW2", field.season = "2016") #' CloseDatabaseConnection(conn) #' } -ChannelFLow <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - channel_flow <- ChannelCharacteristics(conn, path.to.data, park, site, field.season, data.source) %>% +ChannelFLow <- function(park, site, field.season) { + channel_flow <- ChannelCharacteristics(park = park, site = site, field.season = field.season) %>% dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelType) %>% dplyr::summarize(Count = n()) %>% dplyr::mutate(Rank = min_rank(desc(Count))) %>% @@ -195,8 +195,8 @@ ChannelFLow <- function(conn, path.to.data, park, site, field.season, data.sour #' channel_substrate_STRW2_2016 <- ChannelSubstrate(conn, site = "GRBA_S_STRW2", field.season = "2016") #' CloseDatabaseConnection(conn) #' } -ChannelSubstrate <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - channel_substrate <- ChannelCharacteristics(conn, path.to.data, park, site, field.season, data.source) %>% +ChannelSubstrate <- function(park, site, field.season) { + channel_substrate <- ChannelCharacteristics(park = park, site = site, field.season = field.season) %>% dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, Substrate) %>% dplyr::summarize(Count = n()) %>% dplyr::mutate(Rank = min_rank(desc(Count))) %>% @@ -219,8 +219,8 @@ ChannelSubstrate <- function(conn, path.to.data, park, site, field.season, data. #' @return A tibble #' @export #' -BMIFormatted <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi_long <- BMILong(conn, path.to.data, park, site, field.season, data.source) +BMIFormatted <- function(park, site, field.season) { + bmi_long <- BMILong(park = park, site = site, field.season = field.season) bmi_formatted <- bmi_long %>% tidyr::pivot_longer(cols = c("TaxaGroupRichness", "TaxaGroupDensity"), names_to = "Metric", values_to = "Count") @@ -249,8 +249,8 @@ BMIFormatted <- function(conn, path.to.data, park, site, field.season, data.sour #' @return A ggplot object #' @export #' -BMIGeneralMetricsPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) +BMIGeneralMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) bmi.gen <- bmi.formatted %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", @@ -294,8 +294,8 @@ BMIGeneralMetricsPlot <- function(conn, path.to.data, park, site, field.season, #' @return A ggplot object #' @export #' -BMIDiversityMetricsPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) +BMIDiversityMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) bmi.div <- bmi.formatted %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2") %>% @@ -339,8 +339,8 @@ BMIDiversityMetricsPlot <- function(conn, path.to.data, park, site, field.season #' @return A ggplot object #' @export #' -BMIToleranceMetricsPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) +BMIToleranceMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) bmi.tol <- bmi.formatted %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", @@ -383,8 +383,8 @@ BMIToleranceMetricsPlot <- function(conn, path.to.data, park, site, field.season #' @return A ggplot object #' @export #' -BMIFunctionalMetricsPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) +BMIFunctionalMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) bmi.fun <- bmi.formatted %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", @@ -427,8 +427,8 @@ BMIFunctionalMetricsPlot <- function(conn, path.to.data, park, site, field.seaso #' @return A ggplot object #' @export #' -BMITaxonomicMetricsPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) +BMITaxonomicMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) bmi.tax <- bmi.formatted %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", diff --git a/R/calculations.R b/R/calculations.R index cd389e4..a43d738 100644 --- a/R/calculations.R +++ b/R/calculations.R @@ -35,13 +35,13 @@ MaxDQF <- function(flags) { #' @return A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. #' @export #' -LakeWqMedian <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - temp <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "WaterQualityTemperature") - spcond <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "WaterQualitySpCond") - ph <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "WaterQualitypH") - do <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "WaterQualityDO") +LakeWqMedian <- function(park, site, field.season) { + temp <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualityTemperature") + spcond <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualitySpCond") + ph <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualitypH") + do <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualityDO") - wq.visits <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "Visit") + wq.visits <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") temp.med <- temp %>% dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% @@ -101,9 +101,9 @@ LakeWqMedian <- function(conn, path.to.data, park, site, field.season, data.sour #' @return A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. #' @export #' -StreamWqMedian <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - stream_wq <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "WQStreamXSection") - wq.visits <- ReadAndFilterData(conn = conn, path.to.data = path.to.data, park = park, site = site, field.season = field.season, data.source = data.source, data.name = "Visit") +StreamWqMedian <- function(park, site, field.season) { + stream_wq <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WQStreamXSection") + wq.visits <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") stream_wq_med <- stream_wq %>% dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate, MonitoringStatus), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% diff --git a/R/chem-qc.R b/R/chem-qc.R index af97616..1088d1e 100644 --- a/R/chem-qc.R +++ b/R/chem-qc.R @@ -17,8 +17,8 @@ #' qcChemFlags(conn, site = c("GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemFlags <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemFlags <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") flags.list <- chem %>% dplyr::filter(Flag %in% c("I", "W", "C")) %>% @@ -49,8 +49,8 @@ return(flags.list) #' qcChemLabDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemLabDupes <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemLabDupes <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lab.dupes <- chem %>% dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) %>% @@ -109,8 +109,8 @@ qcChemLabDupes <- function(conn, path.to.data, park, site, field.season, data.so #' qcChemFieldDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemFieldDupes <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemFieldDupes <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") field.dupes <- chem %>% dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) %>% @@ -159,8 +159,8 @@ qcChemFieldDupes <- function(conn, path.to.data, park, site, field.season, data. #' qcChemFieldBlanks(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemFieldBlanks <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemFieldBlanks <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lookup <- getMDLLookup() field.blanks <- chem %>% @@ -203,8 +203,8 @@ qcChemFieldBlanks <- function(conn, path.to.data, park, site, field.season, data #' qcChemTDN(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemTDN <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemTDN <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") TDN <- chem %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) %>% @@ -242,8 +242,8 @@ qcChemTDN <- function(conn, path.to.data, park, site, field.season, data.source #' qcChemNO3NO2(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemNO3NO2 <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemNO3NO2 <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") NO3NO2 <- chem %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) %>% @@ -282,8 +282,8 @@ qcChemNO3NO2 <- function(conn, path.to.data, park, site, field.season, data.sour #' qcChemTDP(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemTDP <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemTDP <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") TDP <- chem %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTP", "TDP")) %>% @@ -338,8 +338,8 @@ getMDLLookup <- function() { #' qcChemMDL(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemMDL <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemMDL <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lookup <- getMDLLookup() mdl <- chem %>% @@ -382,8 +382,8 @@ qcChemMDL <- function(conn, path.to.data, park, site, field.season, data.source #' qcChemML(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcChemML <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +qcChemML <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") ml <- chem %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine") %>% @@ -425,9 +425,9 @@ qcChemML <- function(conn, path.to.data, park, site, field.season, data.source = #' ChemANC(conn, site = "GRBA_L_DEAD0", field.season = "2018") #' CloseDatabaseConnection(conn) #' } -ChemANC <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemANC <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") chem.anc.rows <- chem %>% dplyr::filter(Characteristic == "ALK2") %>% @@ -467,9 +467,9 @@ ChemANC <- function(conn, path.to.data, park, site, field.season, data.source = #' CloseDatabaseConnection(conn) #' } #' -ChemLakeANCPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemLakeANCPlot <- function(park, site, field.season) { - chem.anc <- ChemANC(conn, path.to.data, park, site, field.season, data.source) + chem.anc <- ChemANC(park = park, site = site, field.season = field.season) chem.lake.anc <- chem.anc %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC") @@ -514,9 +514,9 @@ ChemLakeANCPlot <- function(conn, path.to.data, park, site, field.season, data.s #' ChemStreamANCPlot(conn, site = "GRBA_S_PINE1") #' CloseDatabaseConnection(conn) #' } -ChemStreamANCPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemStreamANCPlot <- function(park, site, field.season) { - chem.anc <- ChemANC(conn, path.to.data, park, site, field.season, data.source) + chem.anc <- ChemANC(park = park, site = site, field.season = field.season) chem.stream.anc <- chem.anc %>% dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC") @@ -550,9 +550,9 @@ ChemStreamANCPlot <- function(conn, path.to.data, park, site, field.season, data #' @return A ggplot object #' @export #' -ChemLakeNutrientPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemLakeNutrientPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lake.nut <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") %>% @@ -588,9 +588,9 @@ ChemLakeNutrientPlot <- function(conn, path.to.data, park, site, field.season, d #' @return A ggplot object #' @export #' -ChemLakeNutrientBarPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemLakeNutrientBarPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lake.nut.bar <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") %>% @@ -632,9 +632,9 @@ ChemLakeNutrientBarPlot <- function(conn, path.to.data, park, site, field.season #' @return A ggplot object #' @export #' -ChemLakeIonPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemLakeIonPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lake.ion <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Ion", @@ -670,9 +670,9 @@ ChemLakeIonPlot <- function(conn, path.to.data, park, site, field.season, data.s #' @return A ggplot object #' @export #' -ChemStreamNutrientPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemStreamNutrientPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") stream.nut <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") %>% @@ -707,8 +707,8 @@ ChemStreamNutrientPlot <- function(conn, path.to.data, park, site, field.season, #' @return A ggplot object #' @export #' -ChemStreamNutrientBarPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") +ChemStreamNutrientBarPlot <- function(park, site, field.season) { + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") stream.nut.bar <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") %>% @@ -749,9 +749,9 @@ ChemStreamNutrientBarPlot <- function(conn, path.to.data, park, site, field.seas #' @return A ggplot object #' @export #' -ChemStreamIonPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +ChemStreamIonPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") stream.ion <- chem %>% dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Ion", SiteShort != "BAKR2", diff --git a/R/clarity-qc.R b/R/clarity-qc.R index fe69b70..cc6c613 100644 --- a/R/clarity-qc.R +++ b/R/clarity-qc.R @@ -20,11 +20,11 @@ #' qcSecchiGTDepth(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcSecchiGTDepth <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcSecchiGTDepth <- function(park, site, field.season) { - error.list <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "Clarity") + error.list <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Clarity") - error.list %<>% + error.list <- error.list |> dplyr::filter(SecchiDepth_m > DepthToBottom_m) return(error.list) @@ -52,12 +52,12 @@ qcSecchiGTDepth <- function(conn, path.to.data, park, site, field.season, data.s #' qcLakeDryMeasurementsExist(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcLakeDryMeasurementsExist <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcLakeDryMeasurementsExist <- function(park, site, field.season) { - error.list <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "Clarity") + error.list <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Clarity") - error.list %<>% - dplyr::filter(IsLakeDry == TRUE) %>% + error.list <- error.list |> + dplyr::filter(IsLakeDry == TRUE) |> dplyr::filter(!is.na(SurfaceCalm) | !is.na(OnBottom) | !is.na(DepthToBottom_m) | !is.na(SecchiDepth_m)) return(error.list) @@ -85,12 +85,12 @@ qcLakeDryMeasurementsExist <- function(conn, path.to.data, park, site, field.sea #' qcLakeNotDryMeasurementsMissing(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcLakeNotDryMeasurementsMissing <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcLakeNotDryMeasurementsMissing <- function(park, site, field.season) { - error.list <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "Clarity") + error.list <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Clarity") - error.list %<>% - dplyr::filter(IsLakeDry == 0) %>% + error.list <- error.list |> + dplyr::filter(IsLakeDry == 0) |> dplyr::filter(is.na(SurfaceCalm) | is.na(OnBottom) | is.na(DepthToBottom_m)) return(error.list) @@ -118,12 +118,12 @@ qcLakeNotDryMeasurementsMissing <- function(conn, path.to.data, park, site, fiel #' qcDepthMissing(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcSecchiDepthMissing <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcSecchiDepthMissing <- function(park, site, field.season) { - error.list <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "Clarity") + error.list <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Clarity") - error.list %<>% - dplyr::filter(OnBottom == "N") %>% + error.list <- error.list |> + dplyr::filter(OnBottom == "N") |> dplyr::filter(is.na(SecchiDepth_m)) return(error.list) diff --git a/R/efficiency-qc.R b/R/efficiency-qc.R index df6951d..d68c333 100644 --- a/R/efficiency-qc.R +++ b/R/efficiency-qc.R @@ -12,9 +12,9 @@ #' qcNoAnnualVisit(conn, site = "GRBA_L_DEAD0", field.season = c("2012", "2013", "2014", "2015")) #' CloseDatabaseConnection(conn) #' } -qcNoAnnualVisit <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcNoAnnualVisit <- function(park, site, field.season) { -visit.data <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Visit") +visit.data <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") visit <- visit.data %>% dplyr::select(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame, VisitDate, FieldSeason, VisitType, MonitoringStatus) %>% dplyr::filter(VisitType == "Primary", SiteCode != "GRBA_S_BAKR2") %>% @@ -44,20 +44,20 @@ return(visit) #' qcDPLCheck(conn, site = "GRBA_L_JHNS0", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcDPLCheck <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - - visit <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Visit") - chem <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Chemistry") - bmi <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "BMI") - channel <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Channel") - clarity <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Clarity") - lakesurvey <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "LakeLevelSurvey") - lakestring <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "LakeLevelString") - xsection <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "WQStreamXSection") - temp <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "WaterQualityTemperature") - ph <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "WaterQualitypH") - spcond <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "WaterQualitySpCond") - do <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "WaterQualityDO") +qcDPLCheck <- function(park, site, field.season) { + + visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") + chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + # bmi <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMI") + channel <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Channel") + clarity <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Clarity") + lakesurvey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") + lakestring <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") + xsection <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WQStreamXSection") + temp <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualityTemperature") + ph <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualitypH") + spcond <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualitySpCond") + do <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualityDO") visit.DPL <- visit %>% dplyr::rename(Visit.DPL = DataProcessingLevel) %>% @@ -67,10 +67,10 @@ qcDPLCheck <- function(conn, path.to.data, park, site, field.season, data.source dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SampleFrame, DPL) %>% dplyr::rename(Chem.DPL = DPL) %>% dplyr::distinct() - bmi.DPL <- bmi %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(BMI.DPL = DPL) %>% - dplyr::distinct() + # bmi.DPL <- bmi %>% + # dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% + # dplyr::rename(BMI.DPL = DPL) %>% + # dplyr::distinct() channel.DPL <- channel %>% dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, DPL) %>% dplyr::rename(Channel.DPL = DPL) %>% @@ -110,7 +110,7 @@ qcDPLCheck <- function(conn, path.to.data, park, site, field.season, data.source dpl <- visit.DPL %>% dplyr::left_join(chem.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SampleFrame", "VisitType")) %>% - dplyr::left_join(bmi.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% + # dplyr::left_join(bmi.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% dplyr::left_join(channel.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) %>% dplyr::left_join(clarity.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% dplyr::left_join(lakesurvey.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% @@ -143,27 +143,28 @@ return(dpl) #' WqDailyMeanLong(conn, site = "GRBA_S_LHMN1", field.season = c("2012", "2013", "2014", "2015")) #' CloseDatabaseConnection(conn) #' } -WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +WqDailyMeanLong <- function(park, site, field.season) { - wt <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "TimeseriesTemperature") - ph <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "TimeseriespH") - sc <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "TimeseriesSpCond") - do.pct <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "TimeseriesDOSat") - do.mgl <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "TimeseriesDO") - visit <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Visit") + wt <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriesTemperature") + ph <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriespH") + sc <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriesSpCond") + do.pct <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriesDOpct") + do.mgl <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriesDOmgl") + visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") wt.long <- wt %>% dplyr::filter(Approval == "Approved") %>% dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% + dplyr::rename(WaterTemperature_C = Value) %>% dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, Date) %>% - dplyr::summarise(Value = case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(WaterTemperature_C)) > 77 ~ mean(WaterTemperature_C, na.rm = TRUE), + dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(WaterTemperature_C)) > 77 ~ mean(WaterTemperature_C, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(WaterTemperature_C)) > 19 ~ mean(WaterTemperature_C, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = case_when(!is.na(WaterTemperature_C) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% + Grade = dplyr::case_when(!is.na(WaterTemperature_C) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% unique() %>% dplyr::mutate(Parameter = "Temperature") %>% dplyr::mutate(Units = "C") %>% @@ -176,15 +177,16 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s ph.long <- ph %>% dplyr::filter(Approval == "Approved") %>% dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% + dplyr::rename(pH = Value) %>% dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, Date) %>% - dplyr::summarise(Value = case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(pH)) > 77 ~ median(pH, na.rm = TRUE), + dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(pH)) > 77 ~ median(pH, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(pH)) > 19 ~ median(pH, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = case_when(!is.na(pH) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% + Grade = dplyr::case_when(!is.na(pH) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% unique() %>% dplyr::mutate(Parameter = "pH") %>% dplyr::mutate(Units = "units") %>% @@ -197,15 +199,16 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s sc.long <- sc %>% dplyr::filter(Approval == "Approved") %>% dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% + dplyr::rename(SpecificConductance_microS_per_cm = Value) %>% dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, Date) %>% - dplyr::summarise(Value = case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(SpecificConductance_microS_per_cm)) > 77 ~ mean(SpecificConductance_microS_per_cm, na.rm = TRUE), + dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(SpecificConductance_microS_per_cm)) > 77 ~ mean(SpecificConductance_microS_per_cm, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(SpecificConductance_microS_per_cm)) > 19 ~ mean(SpecificConductance_microS_per_cm, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = case_when(!is.na(SpecificConductance_microS_per_cm) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% + Grade = dplyr::case_when(!is.na(SpecificConductance_microS_per_cm) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% unique() %>% dplyr::mutate(Parameter = "SpCond") %>% dplyr::mutate(Units = "uS/cm") %>% @@ -218,15 +221,16 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s do.pct.long <- do.pct %>% dplyr::filter(Approval == "Approved") %>% dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% + dplyr::rename(DissolvedOxygen_percent = Value) %>% dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, Date) %>% - dplyr::summarise(Value = case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_percent)) > 77 ~ mean(DissolvedOxygen_percent, na.rm = TRUE), + dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_percent)) > 77 ~ mean(DissolvedOxygen_percent, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(DissolvedOxygen_percent)) > 19 ~ mean(DissolvedOxygen_percent, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = case_when(!is.na(DissolvedOxygen_percent) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% + Grade = dplyr::case_when(!is.na(DissolvedOxygen_percent) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% unique() %>% dplyr::mutate(Parameter = "DO") %>% dplyr::mutate(Units = "%") %>% @@ -239,16 +243,16 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s do.mgl.long <- do.mgl %>% dplyr::filter(Approval == "Approved") %>% dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% + dplyr::rename(DissolvedOxygen_mgL = Value) %>% dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, Date) %>% - dplyr::rename(DissolvedOxygen_mgL = DissolvedOxygen_mg_per_L) %>% - dplyr::summarise(Value = case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_mgL)) > 77 ~ mean(DissolvedOxygen_mgL, na.rm = TRUE), + dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_mgL)) > 77 ~ mean(DissolvedOxygen_mgL, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(DissolvedOxygen_mgL)) > 19 ~ mean(DissolvedOxygen_mgL, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = case_when(!is.na(DissolvedOxygen_mgL) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% + Grade = dplyr::case_when(!is.na(DissolvedOxygen_mgL) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% unique() %>% dplyr::mutate(Parameter = "DO") %>% dplyr::mutate(Units = "mg/L") %>% @@ -261,16 +265,16 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s wq.long.int <- dplyr::bind_rows(wt.long, ph.long, sc.long, do.pct.long, do.mgl.long) - gage.locations <- tibble::tibble(SiteShort = c("BAKR1", "SNKE1", "SNKE3", "STRW1"), - SiteCode = c("GRBA_S_BAKR1", "GRBA_S_SNKE1", "GRBA_S_SNKE3", "GRBA_S_STRW1"), - SiteName = c("Baker Creek (Gage)", "Snake Creek (Lower)", "Snake Creek (Upper)", "Strawberry Creek (Gage)")) + gage.locations <- tibble::tibble(SiteShort = c("BAKR1", "LHMN1", "SNKE1", "SNKE3", "STRW1"), + SiteCode = c("GRBA_S_BAKR1", "GRBA_S_LHMN1", "GRBA_S_SNKE1", "GRBA_S_SNKE3", "GRBA_S_STRW1"), + SiteName = c("Baker Creek (Gage)", "Lehman Creek (Gage)", "Snake Creek (Lower)", "Snake Creek (Upper)", "Strawberry Creek (Gage)")) visit.names <- visit %>% dplyr::select(SiteShort, SiteCode, SiteName) %>% unique() %>% dplyr::bind_rows(gage.locations) - wq.long <- left_join(wq.long.int, visit.names, by = c("SiteCode")) %>% + wq.long <- dplyr::left_join(wq.long.int, visit.names, by = c("SiteCode")) %>% dplyr::relocate(SiteShort, .before = SiteCode) %>% dplyr::relocate(SiteName, .after = SiteCode) @@ -298,9 +302,9 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s #' WqDailyMean(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -WqDailyMean <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +WqDailyMean <- function(park, site, field.season) { -wq.long <- WqDailyMeanLong(conn, path.to.data, park, site, field.season, data.source) +wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) wq.daily <- wq.long %>% tidyr::unite(Parameter, c("Parameter", "Units")) %>% @@ -343,9 +347,9 @@ return(wq.daily) #' qcWqCompleteness(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcWqCompleteness <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcWqCompleteness <- function(park, site, field.season) { -wq.long <- WqDailyMeanLong(conn, path.to.data, park, site, field.season, data.source) +wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) wq.comp <- wq.long %>% dplyr::mutate(Month = lubridate::month(Date), @@ -362,7 +366,7 @@ wq.comp <- wq.long %>% dplyr::summarise(CompletedDays = sum(!is.na(Value))) %>% dplyr::mutate(PercentCompleteness = CompletedDays/77*100) %>% dplyr::ungroup() %>% - tidyr::complete(FieldSeason, nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(CompletedDays = 0, PercentCompleteness = 0)) %>% + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(CompletedDays = 0, PercentCompleteness = 0)) %>% dplyr::relocate(FieldSeason, .after = SampleFrame) %>% dplyr::arrange(SiteCode, FieldSeason, Parameter) @@ -392,9 +396,9 @@ return(wq.comp) #' qcWqGradesLong(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcWqGradesLong <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcWqGradesLong <- function(park, site, field.season) { -wq.long <- WqDailyMeanLong(conn, path.to.data, park, site, field.season, data.source) +wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) wq.grds.long <- wq.long %>% dplyr::mutate(Month = lubridate::month(Date), @@ -402,10 +406,10 @@ wq.grds.long <- wq.long %>% dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% dplyr::select(-c(Month, Day)) %>% dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Parameter, Units, Grade) %>% - dplyr::summarise(Days = n()) %>% + dplyr::summarise(Days = dplyr::n()) %>% dplyr::mutate(Percent = Days/sum(Days)*100) %>% dplyr::ungroup() %>% - tidyr::complete(FieldSeason, nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(Days = 0, Percent = 0)) %>% + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(Days = 0, Percent = 0)) %>% dplyr::relocate(FieldSeason, .after = SampleFrame) %>% dplyr::arrange(SiteCode, FieldSeason, Parameter, Grade) @@ -434,9 +438,9 @@ return(wq.grds.long) #' qcWqGrades(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcWqGrades <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcWqGrades <- function(park, site, field.season) { -wq.daily <- WqDailyMean(conn, path.to.data, park, site, field.season, data.source) +wq.daily <- WqDailyMean(park = park, site = site, field.season = field.season) wt.grds <- wq.daily %>% dplyr::group_by(Park, @@ -638,20 +642,20 @@ return(wq.grds) #' qcWqCompletenessPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcWqCompletenessPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcWqCompletenessPlot <- function(park, site, field.season) { -wq.comp <- qcWqCompleteness(conn, path.to.data, park, site, field.season, data.source) +wq.comp <- qcWqCompleteness(park = park, site = site, field.season = field.season) wq.comp.concat <- wq.comp %>% tidyr::unite("Parameter", Parameter, Units, sep = "_") wq.comp.concat$Parameter_f = factor(wq.comp.concat$Parameter, levels = c("Temperature_C", "pH_units", "SpCond_uS/cm", "DO_%", "DO_mg/L")) -wq.comp.plot <- ggplot(data = wq.comp.concat, aes(x = FieldSeason, y = PercentCompleteness)) + - geom_bar(stat = "identity", position = position_dodge(), color = "black") + - facet_grid(Parameter_f~SiteCode) + - scale_x_discrete(breaks = scales::pretty_breaks()) + - theme(axis.text.x = element_text(angle = 90), legend.position = "bottom") +wq.comp.plot <- ggplot2::ggplot(data = wq.comp.concat, ggplot2::aes(x = FieldSeason, y = PercentCompleteness)) + + ggplot2::geom_bar(stat = "identity", position = ggplot2::position_dodge(), color = "black") + + ggplot2::facet_grid(Parameter_f~SiteCode) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") return(wq.comp.plot) @@ -677,9 +681,9 @@ return(wq.comp.plot) #' qcWqGradesPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' CloseDatabaseConnection(conn) #' } -qcWqGradesPlot <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +qcWqGradesPlot <- function(park, site, field.season) { -wq.grds.long <- qcWqGradesLong(conn, path.to.data, park, site, field.season, data.source) +wq.grds.long <- qcWqGradesLong(park = park, site = site, field.season = field.season) wq.grds.concat <- wq.grds.long %>% tidyr::unite("Parameter", Parameter, Units, sep = "_") @@ -687,13 +691,13 @@ wq.grds.concat <- wq.grds.long %>% wq.grds.concat$Parameter_f = factor(wq.grds.concat$Parameter, levels = c("Temperature_C", "pH_units", "SpCond_uS/cm", "DO_%", "DO_mg/L")) wq.grds.concat$Grade_f = factor(wq.grds.concat$Grade, levels = c("Excellent", "Est. Excellent", "Good", "Est. Good", "Fair", "Est. Fair", "Poor", "Est. Poor")) -wq.grds.plot <- ggplot(data = wq.grds.concat, aes(x = FieldSeason, y = Percent, fill = Grade_f)) + - geom_col() + - facet_grid(Parameter_f~SiteCode) + - labs(fill = "Grade") + - scale_fill_manual(values = c("forestgreen", "gold", "khaki1", "darkorange", "Red")) + - scale_x_discrete(breaks = scales::pretty_breaks()) + - theme(axis.text.x = element_text(angle = 90), legend.position = "bottom") +wq.grds.plot <- ggplot2::ggplot(data = wq.grds.concat, ggplot2::aes(x = FieldSeason, y = Percent, fill = Grade_f)) + + ggplot2::geom_col() + + ggplot2::facet_grid(Parameter_f~SiteCode) + + ggplot2::labs(fill = "Grade") + + ggplot2::scale_fill_manual(values = c("forestgreen", "gold", "khaki1", "darkorange", "Red")) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") return(wq.grds.plot) diff --git a/R/levels-qc.R b/R/levels-qc.R index fd90ce2..c20f682 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -15,9 +15,9 @@ #' SurveyPointElevation(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -SurveyPointElevation <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - levels.import <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "LakeLevelSurvey") - dry <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "Visit") # Data to filter out dry lakes +SurveyPointElevation <- function(park, site, field.season) { + levels.import <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") + dry <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") # Data to filter out dry lakes StandardTemperature_F <- 68 # Standard temperature to be used for temperature corrections dry %<>% dplyr::select(SiteCode, VisitDate, FieldSeason, IsLakeDry) @@ -121,9 +121,9 @@ SurveyPointElevation <- function(conn, path.to.data, park, site, field.season, d #' LakeSurfaceElevation(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +LakeSurfaceElevation <- function(park, site, field.season) { - t1 <- try(ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "LakeLevelString")) + t1 <- try(ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString")) if("try-error" %in% class(t1)) { string <- tibble::tibble( @@ -141,10 +141,10 @@ LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, d Height_ft = double() ) } else { - string <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "LakeLevelString") + string <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") } - t2 <- try(SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source)) + t2 <- try(SurveyPointElevation(park = park, site = site, field.season = field.season)) if("try-error" %in% class(t2)) { survey <- tibble::tibble( @@ -161,7 +161,7 @@ LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, d BenchmarkUsed = logical() ) } else { - survey <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) %>% + survey <- SurveyPointElevation(park = park, site = site, field.season = field.season) %>% dplyr::filter(Benchmark == "Water Surface") %>% dplyr::mutate(SurveyType = "Digital Level", BenchmarkUsed = NA_character_) %>% @@ -215,8 +215,8 @@ LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, d #' qcBenchmarkElevation(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcBenchmarkElevation <- function(conn, path.to.data, park, site, field.season, data.source = "database", sd_cutoff = NA) { - lvls <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) +qcBenchmarkElevation <- function(park, site, field.season, sd_cutoff = NA) { + lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) lvls %<>% dplyr::select(Park, SiteShort, SiteCode, SiteName, Benchmark, FinalCorrectedElevation_ft) %>% @@ -252,8 +252,8 @@ qcBenchmarkElevation <- function(conn, path.to.data, park, site, field.season, d #' qcStringSurveyHeights(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcStringSurveyHeights <- function(conn, path.to.data, park, site, field.season, data.source = "database", sd_cutoff = NA) { - str_survey <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "LakeLevelString") %>% +qcStringSurveyHeights <- function(park, site, field.season, sd_cutoff = NA) { + str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") %>% dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) %>% dplyr::summarise(MeanHeight_ft = mean(Height_ft), StDevHeight_ft = sd(Height_ft)) %>% @@ -285,8 +285,8 @@ qcStringSurveyHeights <- function(conn, path.to.data, park, site, field.season, #' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcStringSurveyElevations <- function(conn, path.to.data, park, site, field.season, data.source = "database", sd_cutoff = NA) { - str_survey <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, "LakeLevelString") %>% +qcStringSurveyElevations <- function(park, site, field.season, sd_cutoff = NA) { + str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") %>% dplyr::mutate(BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) %>% dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) %>% dplyr::summarise(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) %>% @@ -324,9 +324,9 @@ qcStringSurveyElevations <- function(conn, path.to.data, park, site, field.seaso #' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcElevationDiscrepancies <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - r_elevs <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) - survey_elevs <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "LakeLevelSurvey") +qcElevationDiscrepancies <- function(park, site, field.season) { + r_elevs <- SurveyPointElevation(park = park, site = site, field.season = field.season) + survey_elevs <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") r_elevs_data <- r_elevs %>% dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, SurveyPoint, Benchmark, FinalCorrectedElevation_ft) %>% @@ -375,9 +375,9 @@ qcElevationDiscrepancies <- function(conn, path.to.data, park, site, field.seaso #' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") #' CloseDatabaseConnection(conn) #' } -qcClosureErrorDiscrepancies <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - r_elevs <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) - survey_elevs <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name = "LakeLevelSurvey") +qcClosureErrorDiscrepancies <- function(park, site, field.season) { + r_elevs <- SurveyPointElevation(park = park, site = site, field.season = field.season) + survey_elevs <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") r_ce_data <- r_elevs %>% dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, ClosureError_ft) %>% @@ -416,8 +416,8 @@ qcClosureErrorDiscrepancies <- function(conn, path.to.data, park, site, field.se #' PlotBenchmarkElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) #' CloseDatabaseConnection(conn) #' } -PlotBenchmarkElevation <- function(conn, path.to.data, park, site, field.season, data.source = "database", include.title = TRUE, plotly = FALSE) { - lvls <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) %>% +PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { + lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) %>% dplyr::filter(Benchmark != "Water Surface") %>% tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") @@ -461,8 +461,8 @@ PlotBenchmarkElevation <- function(conn, path.to.data, park, site, field.season, #' PlotLakeSurfaceElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) #' CloseDatabaseConnection(conn) #' } -PlotLakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, data.source = "database", include.title = TRUE, plotly = FALSE) { - elev <- LakeSurfaceElevation(conn, path.to.data, park, site, field.season, data.source) +PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { + elev <- LakeSurfaceElevation(park = park, site = site, field.season = field.season) elev %<>% tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName)) %>% diff --git a/R/wq-qc.R b/R/wq-qc.R index e4a4520..97840ea 100644 --- a/R/wq-qc.R +++ b/R/wq-qc.R @@ -11,8 +11,8 @@ #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m, Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcLakeWqSanity <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - lake.sanity <- qcWqSanity(conn, path.to.data, park, site, field.season, data.source, "lake") +qcLakeWqSanity <- function(park, site, field.season) { + lake.sanity <- qcWqSanity(park = park, site = site, field.season = field.season, wq.type = "lake") return(lake.sanity) } @@ -29,8 +29,8 @@ qcLakeWqSanity <- function(conn, path.to.data, park, site, field.season, data.so #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcStreamWqSanity <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - stream.sanity <- qcWqSanity(conn, path.to.data, park, site, field.season, data.source, "stream") +qcStreamWqSanity <- function(park, site, field.season) { + stream.sanity <- qcWqSanity(park = park, site = site, field.season = field.season, wq.type = "stream") return(stream.sanity) } @@ -48,11 +48,11 @@ qcStreamWqSanity <- function(conn, path.to.data, park, site, field.season, data. #' #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' -qcWqSanity <- function(conn, path.to.data, park, site, field.season, data.source = "database", wq.type) { +qcWqSanity <- function(park, site, field.season, wq.type) { if (wq.type == "stream") { - wq.sanity.predata <- StreamWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.sanity.predata <- StreamWqMedian(park = park, site = site, field.season = field.season) } else if (wq.type == "lake") { - wq.sanity.predata <- LakeWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.sanity.predata <- LakeWqMedian(park = park, site = site, field.season = field.season) } else { stop("Invalid wq.type") } @@ -107,8 +107,8 @@ qcWqSanity <- function(conn, path.to.data, park, site, field.season, data.source #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcLakeWqFlags <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - lake.flags <- qcWqFlags(conn, path.to.data, park, site, field.season, data.source, wq.type = "lake") +qcLakeWqFlags <- function(park, site, field.season) { + lake.flags <- qcWqFlags(park = park, site = site, field.season = field.season, wq.type = "lake") lake.flags %<>% dplyr::filter(!is.na(Median)) @@ -127,8 +127,8 @@ qcLakeWqFlags <- function(conn, path.to.data, park, site, field.season, data.sou #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcStreamWqFlags <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - stream.flags <- qcWqFlags(conn, path.to.data, park, site, field.season, data.source, wq.type = "stream") +qcStreamWqFlags <- function(park, site, field.season) { + stream.flags <- qcWqFlags(park = park, site = site, field.season = field.season, wq.type = "stream") stream.flags %<>% dplyr::filter(!is.na(Median)) @@ -147,11 +147,11 @@ qcStreamWqFlags <- function(conn, path.to.data, park, site, field.season, data.s #' #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' -qcWqFlags <- function(conn, path.to.data, park, site, field.season, data.source = "database", wq.type) { +qcWqFlags <- function(park, site, field.season, wq.type) { if (wq.type == "stream") { - wq.flags.predata <- StreamWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.flags.predata <- StreamWqMedian(park = park, site = site, field.season = field.season) } else if (wq.type == "lake") { - wq.flags.predata <- LakeWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.flags.predata <- LakeWqMedian(park = park, site = site, field.season = field.season) } else { stop("Invalid wq.type") } @@ -207,8 +207,8 @@ qcWqFlags <- function(conn, path.to.data, park, site, field.season, data.source #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcLakeWqCleaned <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - lake_cleaned <- qcWqCleaned(conn, path.to.data, park, site, field.season, data.source, "lake") +qcLakeWqCleaned <- function(park, site, field.season) { + lake_cleaned <- qcWqCleaned(park = park, site = site, field.season = field.season, wq.type = "lake") return(lake_cleaned) } @@ -225,8 +225,8 @@ qcLakeWqCleaned <- function(conn, path.to.data, park, site, field.season, data.s #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcStreamWqCleaned <- function(conn, path.to.data, park, site, field.season, data.source = "database") { - stream_cleaned <- qcWqCleaned(conn, path.to.data, park, site, field.season, data.source, "stream") +qcStreamWqCleaned <- function(park, site, field.season) { + stream_cleaned <- qcWqCleaned(park = park, site = site, field.season = field.season, wq.type = "stream") return(stream_cleaned) } @@ -243,11 +243,11 @@ qcStreamWqCleaned <- function(conn, path.to.data, park, site, field.season, data #' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. #' @export #' -qcWqCleaned <- function(conn, path.to.data, park, site, field.season, data.source = "database", wq.type) { +qcWqCleaned <- function(park, site, field.season, wq.type) { if (wq.type == "stream") { - wq.sanity.predata <- StreamWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.sanity.predata <- StreamWqMedian(park = park, site = site, field.season = field.season) } else if (wq.type == "lake") { - wq.sanity.predata <- LakeWqMedian(conn, path.to.data, park, site, field.season, data.source) + wq.sanity.predata <- LakeWqMedian(park = park, site = site, field.season = field.season) } else { stop("Invalid wq.type") } @@ -302,9 +302,9 @@ qcWqCleaned <- function(conn, path.to.data, park, site, field.season, data.sourc #' @return Depth profile plot for lake water quality. #' @export #' -WqPlotPHDepthProfile <- function(conn, path.to.data, park, site, field.season, include.title = TRUE, plotly = FALSE, data.source = "database") { +WqPlotPHDepthProfile <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { - plot_ph <- WqPlotDepthProfile(conn = conn, path.to.data = path.to.data, param = "pH", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly, data.source = data.source) + plot_ph <- WqPlotDepthProfile(param = "pH", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly) return(plot_ph) } @@ -324,9 +324,9 @@ WqPlotPHDepthProfile <- function(conn, path.to.data, park, site, field.season, i #' @return Depth profile plot for lake water quality. #' @export #' -WqPlotDODepthProfile <- function(conn, path.to.data, units = "mg/L", park, site, field.season, include.title = TRUE, plotly = FALSE, data.source = "database") { +WqPlotDODepthProfile <- function(units = "mg/L", park, site, field.season, include.title = TRUE, plotly = FALSE) { - plot_do <- WqPlotDepthProfile(conn = conn, path.to.data = path.to.data, param = "DO", units = units, park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly, data.source = data.source) + plot_do <- WqPlotDepthProfile(param = "DO", units = units, park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly) return(plot_do) } @@ -345,9 +345,9 @@ WqPlotDODepthProfile <- function(conn, path.to.data, units = "mg/L", park, site, #' @return Depth profile plot for lake water quality. #' @export #' -WqPlotSpCondDepthProfile <- function(conn, path.to.data, park, site, field.season, include.title = TRUE, plotly = FALSE, data.source = "database") { +WqPlotSpCondDepthProfile <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { - plot_spcond <- WqPlotDepthProfile(conn = conn, path.to.data = path.to.data, param = "SpCond", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly, data.source = data.source) + plot_spcond <- WqPlotDepthProfile(param = "SpCond", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly) return(plot_spcond) } @@ -359,9 +359,9 @@ WqPlotSpCondDepthProfile <- function(conn, path.to.data, park, site, field.seaso #' @return Depth profile plot for lake water quality. #' @export #' -WqPlotTemperatureDepthProfile <- function(conn, path.to.data, park, site, field.season, include.title = TRUE, plotly = FALSE, data.source = "database") { +WqPlotTemperatureDepthProfile <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { - plot_temp <- WqPlotDepthProfile(conn = conn, path.to.data = path.to.data, param = "Temperature", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly, data.source = data.source) + plot_temp <- WqPlotDepthProfile(param = "Temperature", park = park, site = site, field.season = field.season, include.title = include.title, plotly = plotly) return(plot_temp) } @@ -376,9 +376,9 @@ WqPlotTemperatureDepthProfile <- function(conn, path.to.data, park, site, field. #' #' @return Depth profile plot for lake water quality. #' -WqPlotDepthProfile <- function(conn, path.to.data, param, units, park, site, field.season, include.title = TRUE, plotly = FALSE, data.source = "database") { +WqPlotDepthProfile <- function(param, units, park, site, field.season, include.title = TRUE, plotly = FALSE) { - wq <- qcLakeWqCleaned(conn, path.to.data, park, site, field.season, data.source) %>% + wq <- qcLakeWqCleaned(param = param, units = units, park = park, site = site, field.season = field.season) %>% dplyr::filter(tolower(Parameter) == tolower(param), !is.na(Median)) %>% dplyr::rename(Depth_m = MeasurementDepth_m) diff --git a/man/BMIDiversityMetricsPlot.Rd b/man/BMIDiversityMetricsPlot.Rd index a6e2f97..9609afd 100644 --- a/man/BMIDiversityMetricsPlot.Rd +++ b/man/BMIDiversityMetricsPlot.Rd @@ -4,26 +4,19 @@ \alias{BMIDiversityMetricsPlot} \title{Plot diversity-related metrics and indices for each BMI sample.} \usage{ -BMIDiversityMetricsPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMIDiversityMetricsPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMIFormatted.Rd b/man/BMIFormatted.Rd index bb7345f..5febd08 100644 --- a/man/BMIFormatted.Rd +++ b/man/BMIFormatted.Rd @@ -4,26 +4,19 @@ \alias{BMIFormatted} \title{Intermediate step used to pivot BMI data to an even longer format for ease of plotting} \usage{ -BMIFormatted( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMIFormatted(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMIFunctionalMetricsPlot.Rd b/man/BMIFunctionalMetricsPlot.Rd index 59bd65b..276de71 100644 --- a/man/BMIFunctionalMetricsPlot.Rd +++ b/man/BMIFunctionalMetricsPlot.Rd @@ -4,26 +4,19 @@ \alias{BMIFunctionalMetricsPlot} \title{Plot functional feeding group-related richness and abundance metrics for each BMI sample.} \usage{ -BMIFunctionalMetricsPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMIFunctionalMetricsPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMIGeneralMetricsPlot.Rd b/man/BMIGeneralMetricsPlot.Rd index 10d32b3..8c50029 100644 --- a/man/BMIGeneralMetricsPlot.Rd +++ b/man/BMIGeneralMetricsPlot.Rd @@ -4,26 +4,19 @@ \alias{BMIGeneralMetricsPlot} \title{Plot overall richness and abundance metrics for each BMI sample.} \usage{ -BMIGeneralMetricsPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMIGeneralMetricsPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMILong.Rd b/man/BMILong.Rd index 475b748..9e73fd9 100644 --- a/man/BMILong.Rd +++ b/man/BMILong.Rd @@ -4,19 +4,19 @@ \alias{BMILong} \title{Pivot BMI data to long format} \usage{ -BMILong(conn, path.to.data, park, site, field.season, data.source = "database") +BMILong(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMITaxonomicMetricsPlot.Rd b/man/BMITaxonomicMetricsPlot.Rd index 23e9cd2..de5ddcc 100644 --- a/man/BMITaxonomicMetricsPlot.Rd +++ b/man/BMITaxonomicMetricsPlot.Rd @@ -4,26 +4,19 @@ \alias{BMITaxonomicMetricsPlot} \title{Plot taxonomic-related richness and abundance metrics for each BMI sample.} \usage{ -BMITaxonomicMetricsPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMITaxonomicMetricsPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/BMIToleranceMetricsPlot.Rd b/man/BMIToleranceMetricsPlot.Rd index 3fb8aad..9561876 100644 --- a/man/BMIToleranceMetricsPlot.Rd +++ b/man/BMIToleranceMetricsPlot.Rd @@ -4,26 +4,19 @@ \alias{BMIToleranceMetricsPlot} \title{Plot tolerance-related richness and abundance metrics for each BMI sample.} \usage{ -BMIToleranceMetricsPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +BMIToleranceMetricsPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChannelCharacteristics.Rd b/man/ChannelCharacteristics.Rd index 1826e9a..b09f534 100644 --- a/man/ChannelCharacteristics.Rd +++ b/man/ChannelCharacteristics.Rd @@ -4,26 +4,19 @@ \alias{ChannelCharacteristics} \title{Filter channel characteristic data by primary visit type} \usage{ -ChannelCharacteristics( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChannelCharacteristics(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChannelFLow.Rd b/man/ChannelFLow.Rd index 25ef594..7db749e 100644 --- a/man/ChannelFLow.Rd +++ b/man/ChannelFLow.Rd @@ -4,26 +4,19 @@ \alias{ChannelFLow} \title{Rank channel flow type by count for each BMI sample} \usage{ -ChannelFLow( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChannelFLow(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChannelSubstrate.Rd b/man/ChannelSubstrate.Rd index 486b548..e4b866e 100644 --- a/man/ChannelSubstrate.Rd +++ b/man/ChannelSubstrate.Rd @@ -4,26 +4,19 @@ \alias{ChannelSubstrate} \title{Rank channel substrate type by count for each BMI sample} \usage{ -ChannelSubstrate( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChannelSubstrate(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChemANC.Rd b/man/ChemANC.Rd index fcc8e64..be70dea 100644 --- a/man/ChemANC.Rd +++ b/man/ChemANC.Rd @@ -4,19 +4,19 @@ \alias{ChemANC} \title{Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2)} \usage{ -ChemANC(conn, path.to.data, park, site, field.season, data.source = "database") +ChemANC(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChemLakeANCPlot.Rd b/man/ChemLakeANCPlot.Rd index 099a64e..e7896cb 100644 --- a/man/ChemLakeANCPlot.Rd +++ b/man/ChemLakeANCPlot.Rd @@ -4,26 +4,19 @@ \alias{ChemLakeANCPlot} \title{Plot acid neutralizing capacity (ANC) at lakes, and include EPA thresholds} \usage{ -ChemLakeANCPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemLakeANCPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChemLakeIonPlot.Rd b/man/ChemLakeIonPlot.Rd index 7491823..051f0ed 100644 --- a/man/ChemLakeIonPlot.Rd +++ b/man/ChemLakeIonPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemLakeIonPlot} \title{Plot lake ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons.} \usage{ -ChemLakeIonPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemLakeIonPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/ChemLakeNutrientBarPlot.Rd b/man/ChemLakeNutrientBarPlot.Rd index d81fc6e..3426a59 100644 --- a/man/ChemLakeNutrientBarPlot.Rd +++ b/man/ChemLakeNutrientBarPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemLakeNutrientBarPlot} \title{Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP) concentration data as overlapping bar plots for all parks and field seasons.} \usage{ -ChemLakeNutrientBarPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemLakeNutrientBarPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/ChemLakeNutrientPlot.Rd b/man/ChemLakeNutrientPlot.Rd index 9dcbed8..413dc00 100644 --- a/man/ChemLakeNutrientPlot.Rd +++ b/man/ChemLakeNutrientPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemLakeNutrientPlot} \title{Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons.} \usage{ -ChemLakeNutrientPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemLakeNutrientPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/ChemStreamANCPlot.Rd b/man/ChemStreamANCPlot.Rd index 2e930ff..2da1cd8 100644 --- a/man/ChemStreamANCPlot.Rd +++ b/man/ChemStreamANCPlot.Rd @@ -4,26 +4,19 @@ \alias{ChemStreamANCPlot} \title{Plot acid neutralizing capacity (ANC) at streams, and include EPA thresholds} \usage{ -ChemStreamANCPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemStreamANCPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/ChemStreamIonPlot.Rd b/man/ChemStreamIonPlot.Rd index cd46f2f..7a44347 100644 --- a/man/ChemStreamIonPlot.Rd +++ b/man/ChemStreamIonPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemStreamIonPlot} \title{Plot stream ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons.} \usage{ -ChemStreamIonPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemStreamIonPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/ChemStreamNutrientBarPlot.Rd b/man/ChemStreamNutrientBarPlot.Rd index a5c4dc1..f3fdd6f 100644 --- a/man/ChemStreamNutrientBarPlot.Rd +++ b/man/ChemStreamNutrientBarPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemStreamNutrientBarPlot} \title{Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP) concentration data as overlapping bar plots for all parks and field seasons.} \usage{ -ChemStreamNutrientBarPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemStreamNutrientBarPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/ChemStreamNutrientPlot.Rd b/man/ChemStreamNutrientPlot.Rd index bb1d6d6..58985b1 100644 --- a/man/ChemStreamNutrientPlot.Rd +++ b/man/ChemStreamNutrientPlot.Rd @@ -4,27 +4,14 @@ \alias{ChemStreamNutrientPlot} \title{Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons.} \usage{ -ChemStreamNutrientPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +ChemStreamNutrientPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/GetAGOLColSpec.Rd b/man/GetAGOLColSpec.Rd new file mode 100644 index 0000000..c5e1d00 --- /dev/null +++ b/man/GetAGOLColSpec.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{GetAGOLColSpec} +\alias{GetAGOLColSpec} +\title{Get column specifications for AGOL database} +\usage{ +GetAGOLColSpec() +} +\value{ +A list of column specifications for each table of Aquarius data. +} +\description{ +Get column specifications for AGOL database +} diff --git a/man/GetAquariusColSpec.Rd b/man/GetAquariusColSpec.Rd index 043964e..63b5e62 100644 --- a/man/GetAquariusColSpec.Rd +++ b/man/GetAquariusColSpec.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/utils.R \name{GetAquariusColSpec} \alias{GetAquariusColSpec} -\title{Get column specifications for Aquarius data that have been written to csv.} +\title{Get column specifications for Aquarius database} \usage{ GetAquariusColSpec() } \value{ -A list of column specifications for each csv of Aquarius data. +A list of column specifications for each table of Aquarius data. } \description{ -Get column specifications for Aquarius data that have been written to csv. +Get column specifications for Aquarius database } diff --git a/man/GetColSpec.Rd b/man/GetColSpec.Rd index 19d6b75..69fede2 100644 --- a/man/GetColSpec.Rd +++ b/man/GetColSpec.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/utils.R \name{GetColSpec} \alias{GetColSpec} -\title{Get column specifications} +\title{Get column specifications for SQL database} \usage{ GetColSpec() } \value{ -A list of column specifications for each table of data. +A list of column specifications for each table of SQL data. } \description{ -Get column specifications +Get column specifications for SQL database } diff --git a/man/LakeSurfaceElevation.Rd b/man/LakeSurfaceElevation.Rd index a8d32f6..4c00acd 100644 --- a/man/LakeSurfaceElevation.Rd +++ b/man/LakeSurfaceElevation.Rd @@ -4,27 +4,14 @@ \alias{LakeSurfaceElevation} \title{Calculates lake level elevations} \usage{ -LakeSurfaceElevation( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +LakeSurfaceElevation(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason,VisitType, DPL, SurveyType, BenchmarkUsed, ClosureError_ft, FinalElevation_ft. diff --git a/man/LakeWqMedian.Rd b/man/LakeWqMedian.Rd index a8d50af..0260db3 100644 --- a/man/LakeWqMedian.Rd +++ b/man/LakeWqMedian.Rd @@ -4,26 +4,19 @@ \alias{LakeWqMedian} \title{Calculate median values for each water quality parameter for each lake visit.} \usage{ -LakeWqMedian( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +LakeWqMedian(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/LoadStreamsAndLakes.Rd b/man/LoadStreamsAndLakes.Rd new file mode 100644 index 0000000..117f1bb --- /dev/null +++ b/man/LoadStreamsAndLakes.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{LoadStreamsAndLakes} +\alias{LoadStreamsAndLakes} +\title{Load raw data into package environment} +\usage{ +LoadStreamsAndLakes( + data_path = c("database", "aquarius", bmi_db = + "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", + calibration_db = + "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer"), + use_default_sql = TRUE, + sql_drv = odbc::odbc(), + agol_username = "mojn_data", + agol_password = + rstudioapi::askForPassword(paste("Please enter the password for AGOL account", + agol_username)), + ... +) +} +\arguments{ +\item{data_path}{A path or URL to the data. Accepted inputs: +\itemize{ +\item 2 URLs to the AGOL feature services containing the data (bmi_db and calibration_db) +\item a folder containing the data in csv format +\item a .zip file containing the data in csv format +\item \code{"database"} (connect to the SQL server database) +\item \code{"aquarius"} (connect to the Aquarius database) +}} + +\item{use_default_sql}{Use default SQL database? Ignored if \code{data_path != "database"}.} + +\item{sql_drv}{Driver to use to connect to database. Ignored if \code{data_path != "database"}.} + +\item{...}{} +} +\value{ +Invisibly return a list containing all raw data +} +\description{ +Run this function before you do anything else. +} +\examples{ +\dontrun{ +LoadStreamsAndLakes() # Read from all sources (e.g., AGOL, SQL, Aquarius, CSVs) +LoadStreamsAndLakes("aquarius") # Read from Aquarius database only +LoadStreamsAndLakes("path/to/csv/folder") # Read from folder of CSVs +LoadStreamsAndLakes("path/to/zipped/csvs.zip") # Read from zip file of CSVs +} +} diff --git a/man/OpenDatabaseConnection.Rd b/man/OpenDatabaseConnection.Rd index c7f55d8..45d3110 100644 --- a/man/OpenDatabaseConnection.Rd +++ b/man/OpenDatabaseConnection.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{OpenDatabaseConnection} \alias{OpenDatabaseConnection} -\title{Open a Connection to the MOJN Streams and Lakes Database} +\title{Open a connection to the Streams and Lakes Database} \usage{ OpenDatabaseConnection(use.mojn.default = TRUE, drv = odbc::odbc(), ...) } @@ -17,7 +17,7 @@ OpenDatabaseConnection(use.mojn.default = TRUE, drv = odbc::odbc(), ...) A database connection pool object } \description{ -Open a Connection to the MOJN Streams and Lakes Database +Open a connection to the Streams and Lakes Database } \examples{ \dontrun{ diff --git a/man/PlotBenchmarkElevation.Rd b/man/PlotBenchmarkElevation.Rd index 6936852..72fad83 100644 --- a/man/PlotBenchmarkElevation.Rd +++ b/man/PlotBenchmarkElevation.Rd @@ -5,29 +5,20 @@ \title{Plot benchmark elevations over time} \usage{ PlotBenchmarkElevation( - conn, - path.to.data, park, site, field.season, - data.source = "database", include.title = TRUE, plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} diff --git a/man/PlotLakeSurfaceElevation.Rd b/man/PlotLakeSurfaceElevation.Rd index 8015ea8..48eec0a 100644 --- a/man/PlotLakeSurfaceElevation.Rd +++ b/man/PlotLakeSurfaceElevation.Rd @@ -5,29 +5,20 @@ \title{Plot lake surface elevations over time} \usage{ PlotLakeSurfaceElevation( - conn, - path.to.data, park, site, field.season, - data.source = "database", include.title = TRUE, plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} diff --git a/man/ReadAGOL.Rd b/man/ReadAGOL.Rd new file mode 100644 index 0000000..f1a7f04 --- /dev/null +++ b/man/ReadAGOL.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{ReadAGOL} +\alias{ReadAGOL} +\title{Read data from the Streams and Lakes AGOL feature layer} +\usage{ +ReadAGOL(...) +} +\arguments{ +\item{...}{} +} +\value{ +A list of tibbles +} +\description{ +Read data from the Streams and Lakes AGOL feature layer +} diff --git a/man/ReadAndFilterData.Rd b/man/ReadAndFilterData.Rd index 4e03283..fc6b373 100644 --- a/man/ReadAndFilterData.Rd +++ b/man/ReadAndFilterData.Rd @@ -14,12 +14,6 @@ ReadAndFilterData(park, site, field.season, data.name) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} \item{data.name}{The name of the analysis view or the csv file containing the data. E.g. "CalibrationDO", "DischargeVolumetric". See details for full list of data name options.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble of filtered data. @@ -28,5 +22,5 @@ A tibble of filtered data. Read Streams and Lakes data from database or .csv } \details{ -\code{data.name} options are: Site, Visit, BMI, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature +\code{data.name} options are: Site, Visit, BMIVisit, BMIMetrics, BMISpecies, Channel, Chemistry, Clarity, WaterQualityDO, WaterQualitypH, WaterQualitySpCond, WaterQualityTemperature, WQStreamXSection, CalibrationDO, CalibrationpH, CalibrationSpCond, TimeseriesDOmgl, TimeseriesDOpct, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature, TimeseriesDischarge, TimeseriesWaterLevel } diff --git a/man/ReadAquarius.Rd b/man/ReadAquarius.Rd new file mode 100644 index 0000000..0d86daa --- /dev/null +++ b/man/ReadAquarius.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{ReadAquarius} +\alias{ReadAquarius} +\title{Read data from the Aquarius database} +\usage{ +ReadAquarius(...) +} +\value{ +A list of tibbles +} +\description{ +Read data from the Aquarius database +} diff --git a/man/ReadAquariusStreams.Rd b/man/ReadAquariusStreams.Rd deleted file mode 100644 index 7ce930b..0000000 --- a/man/ReadAquariusStreams.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{ReadAquariusStreams} -\alias{ReadAquariusStreams} -\title{Read Streams and Lakes data from Aquarius} -\usage{ -ReadAquariusStreams() -} -\arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{data.name}{The name of the data table. E.g. "TimeseriesDO". See details for full list of data name options.} -} -\value{ -A tibble of Aquarius data, wrangled and formatted. -} -\description{ -Read Streams and Lakes data from Aquarius -} -\details{ -\code{data.name} options are: TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature -} diff --git a/man/ReadCSV.Rd b/man/ReadCSV.Rd new file mode 100644 index 0000000..4f7c7bb --- /dev/null +++ b/man/ReadCSV.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{ReadCSV} +\alias{ReadCSV} +\title{Title} +\usage{ +ReadCSV(data_path) +} +\arguments{ +\item{data_path}{} +} +\description{ +Title +} diff --git a/man/ReadSqlDatabase.Rd b/man/ReadSqlDatabase.Rd new file mode 100644 index 0000000..e789899 --- /dev/null +++ b/man/ReadSqlDatabase.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{ReadSqlDatabase} +\alias{ReadSqlDatabase} +\title{Read data from the Streams and Lakes SQL database} +\usage{ +ReadSqlDatabase(...) +} +\arguments{ +\item{...}{Optional arguments to be passed to \code{OpenDatabaseConnection()}} +} +\value{ +A list of tibbles +} +\description{ +Read data from the Streams and Lakes SQL database +} diff --git a/man/StreamWqMedian.Rd b/man/StreamWqMedian.Rd index ead392f..c44ffda 100644 --- a/man/StreamWqMedian.Rd +++ b/man/StreamWqMedian.Rd @@ -4,26 +4,19 @@ \alias{StreamWqMedian} \title{Calculate median values for each water quality parameter for each stream visit.} \usage{ -StreamWqMedian( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +StreamWqMedian(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/SurveyPointElevation.Rd b/man/SurveyPointElevation.Rd index 2aec25a..f1b98c5 100644 --- a/man/SurveyPointElevation.Rd +++ b/man/SurveyPointElevation.Rd @@ -4,27 +4,14 @@ \alias{SurveyPointElevation} \title{Calculates mean elevations for each survey point type in a survey} \usage{ -SurveyPointElevation( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +SurveyPointElevation(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason,VisitType, DPL, SurveyPoint, Benchmark, FinalCorrectedElevation_ft. diff --git a/man/WqDailyMean.Rd b/man/WqDailyMean.Rd index ce49d29..976335b 100644 --- a/man/WqDailyMean.Rd +++ b/man/WqDailyMean.Rd @@ -4,26 +4,19 @@ \alias{WqDailyMean} \title{Return summary of daily mean values (daily median values for pH) and grades for water quality parameters at streams.} \usage{ -WqDailyMean( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +WqDailyMean(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/WqDailyMeanLong.Rd b/man/WqDailyMeanLong.Rd index ec43654..e7d19e6 100644 --- a/man/WqDailyMeanLong.Rd +++ b/man/WqDailyMeanLong.Rd @@ -4,27 +4,14 @@ \alias{WqDailyMeanLong} \title{Calculate daily mean values (daily median values for pH) for water quality parameters at streams based on hourly data. Determine the most frequent data grade level for each day based on hourly data. Include only those dates with greater than 80\% completeness (greater than 19 hourly values). Long format for ease of plotting.} \usage{ -WqDailyMeanLong( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +WqDailyMeanLong(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Date, Parameter, Units, Value, Grade. diff --git a/man/WqPlotDODepthProfile.Rd b/man/WqPlotDODepthProfile.Rd index b64cb46..9a7b4ef 100644 --- a/man/WqPlotDODepthProfile.Rd +++ b/man/WqPlotDODepthProfile.Rd @@ -5,22 +5,15 @@ \title{Generate lake DO depth profile plots.} \usage{ WqPlotDODepthProfile( - conn, - path.to.data, units = "mg/L", park, site, field.season, include.title = TRUE, - plotly = FALSE, - data.source = "database" + plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{units}{Dissolved oxygen units. One of "mg/L" (default) or "\%".} \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} @@ -33,6 +26,10 @@ WqPlotDODepthProfile( \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/WqPlotDepthProfile.Rd b/man/WqPlotDepthProfile.Rd index 3a3c951..c4e9a4c 100644 --- a/man/WqPlotDepthProfile.Rd +++ b/man/WqPlotDepthProfile.Rd @@ -5,23 +5,16 @@ \title{Generate lake depth profile plots.} \usage{ WqPlotDepthProfile( - conn, - path.to.data, param, units, park, site, field.season, include.title = TRUE, - plotly = FALSE, - data.source = "database" + plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{param}{The water quality parameter to plot. One of "pH", "DO", "SpCond", or "Temperature".} \item{units}{Units of dissolved oxygen. Either "mg/L" or "\%". Ignored if \code{param != "DO"}.} @@ -35,8 +28,6 @@ WqPlotDepthProfile( \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ Depth profile plot for lake water quality. diff --git a/man/WqPlotPHDepthProfile.Rd b/man/WqPlotPHDepthProfile.Rd index 63da24e..395dd88 100644 --- a/man/WqPlotPHDepthProfile.Rd +++ b/man/WqPlotPHDepthProfile.Rd @@ -5,21 +5,14 @@ \title{Generate lake pH depth profile plots.} \usage{ WqPlotPHDepthProfile( - conn, - path.to.data, park, site, field.season, include.title = TRUE, - plotly = FALSE, - data.source = "database" + plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} @@ -30,6 +23,10 @@ WqPlotPHDepthProfile( \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/WqPlotSpCondDepthProfile.Rd b/man/WqPlotSpCondDepthProfile.Rd index 072278b..f947000 100644 --- a/man/WqPlotSpCondDepthProfile.Rd +++ b/man/WqPlotSpCondDepthProfile.Rd @@ -5,21 +5,14 @@ \title{Generate lake specific conductance depth profile plots.} \usage{ WqPlotSpCondDepthProfile( - conn, - path.to.data, park, site, field.season, include.title = TRUE, - plotly = FALSE, - data.source = "database" + plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} @@ -30,6 +23,10 @@ WqPlotSpCondDepthProfile( \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/WqPlotTemperatureDepthProfile.Rd b/man/WqPlotTemperatureDepthProfile.Rd index 733d50b..417e3a1 100644 --- a/man/WqPlotTemperatureDepthProfile.Rd +++ b/man/WqPlotTemperatureDepthProfile.Rd @@ -5,21 +5,14 @@ \title{Generate lake temperature depth profile plots.} \usage{ WqPlotTemperatureDepthProfile( - conn, - path.to.data, park, site, field.season, include.title = TRUE, - plotly = FALSE, - data.source = "database" + plotly = FALSE ) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} @@ -29,8 +22,6 @@ WqPlotTemperatureDepthProfile( \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ Depth profile plot for lake water quality. diff --git a/man/fetchAndWrangleBMI.Rd b/man/fetchAndWrangleAGOL.Rd similarity index 66% rename from man/fetchAndWrangleBMI.Rd rename to man/fetchAndWrangleAGOL.Rd index c523c16..96c4a5a 100644 --- a/man/fetchAndWrangleBMI.Rd +++ b/man/fetchAndWrangleAGOL.Rd @@ -1,13 +1,16 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R -\name{fetchAndWrangleBMI} -\alias{fetchAndWrangleBMI} +\name{fetchAndWrangleAGOL} +\alias{fetchAndWrangleAGOL} \title{Fetch BMI data from AGOL and do preliminary data wrangling} \usage{ -fetchAndWrangleBMI( +fetchAndWrangleAGOL( bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", - agol_username = "mojn_data" + calibration_url = + "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer", + agol_username = "mojn_data", + show_col_types = FALSE ) } \arguments{ diff --git a/man/qcBMIDiscrepancies.Rd b/man/qcBMIDiscrepancies.Rd index 0b5ddef..e390e25 100644 --- a/man/qcBMIDiscrepancies.Rd +++ b/man/qcBMIDiscrepancies.Rd @@ -4,26 +4,19 @@ \alias{qcBMIDiscrepancies} \title{Check for discrepancies between taxa count and abundance} \usage{ -qcBMIDiscrepancies( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcBMIDiscrepancies(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcBenchmarkElevation.Rd b/man/qcBenchmarkElevation.Rd index 6bcd416..9527aff 100644 --- a/man/qcBenchmarkElevation.Rd +++ b/man/qcBenchmarkElevation.Rd @@ -4,29 +4,15 @@ \alias{qcBenchmarkElevation} \title{Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons} \usage{ -qcBenchmarkElevation( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) +qcBenchmarkElevation(park, site, field.season, sd_cutoff = NA) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ diff --git a/man/qcChemFieldBlanks.Rd b/man/qcChemFieldBlanks.Rd index 5141913..90eb3df 100644 --- a/man/qcChemFieldBlanks.Rd +++ b/man/qcChemFieldBlanks.Rd @@ -4,26 +4,19 @@ \alias{qcChemFieldBlanks} \title{List all laboratory values from field blanks that exceed the minimum detection level (MDL) for that analyte.} \usage{ -qcChemFieldBlanks( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemFieldBlanks(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemFieldDupes.Rd b/man/qcChemFieldDupes.Rd index edd2c32..784ab43 100644 --- a/man/qcChemFieldDupes.Rd +++ b/man/qcChemFieldDupes.Rd @@ -4,26 +4,19 @@ \alias{qcChemFieldDupes} \title{Calculate the relative percent difference (RPD) for field duplicates, flag results that exceed the 30\% MQO threshold, and list all RPD values and flags.} \usage{ -qcChemFieldDupes( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemFieldDupes(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemFlags.Rd b/man/qcChemFlags.Rd index 33752b9..5627e36 100644 --- a/man/qcChemFlags.Rd +++ b/man/qcChemFlags.Rd @@ -4,26 +4,19 @@ \alias{qcChemFlags} \title{List all laboratory values that have an "Information," "Warning," or "Critical" flag.} \usage{ -qcChemFlags( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemFlags(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemLabDupes.Rd b/man/qcChemLabDupes.Rd index b48fbcf..bc598f2 100644 --- a/man/qcChemLabDupes.Rd +++ b/man/qcChemLabDupes.Rd @@ -4,26 +4,19 @@ \alias{qcChemLabDupes} \title{Calculate the relative percent difference (RPD) for laboratory duplicates and triplicates, flag results that exceed the 30\% MQO threshold, and list all RPD values and flags.} \usage{ -qcChemLabDupes( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemLabDupes(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemMDL.Rd b/man/qcChemMDL.Rd index f96a81c..f1c994a 100644 --- a/man/qcChemMDL.Rd +++ b/man/qcChemMDL.Rd @@ -4,26 +4,19 @@ \alias{qcChemMDL} \title{List all routine laboratory values that are less than or equal to the minimum detection level (MDL) for that analyte.} \usage{ -qcChemMDL( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemMDL(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemML.Rd b/man/qcChemML.Rd index 0261a4d..919fb78 100644 --- a/man/qcChemML.Rd +++ b/man/qcChemML.Rd @@ -4,26 +4,19 @@ \alias{qcChemML} \title{List all routine laboratory values that are less than or equal to the minimum level of quantitation (ML) for that analyte.} \usage{ -qcChemML( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemML(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemNO3NO2.Rd b/man/qcChemNO3NO2.Rd index 6427bbb..c47dabb 100644 --- a/man/qcChemNO3NO2.Rd +++ b/man/qcChemNO3NO2.Rd @@ -4,26 +4,19 @@ \alias{qcChemNO3NO2} \title{List all routine samples where nitrate and nitrite (NO3NO2-N) values exceeded either total dissolved nitrogen (TDN) values or total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error.} \usage{ -qcChemNO3NO2( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemNO3NO2(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemTDN.Rd b/man/qcChemTDN.Rd index 2f8b37d..66e30f1 100644 --- a/man/qcChemTDN.Rd +++ b/man/qcChemTDN.Rd @@ -4,26 +4,19 @@ \alias{qcChemTDN} \title{List all routine samples where total dissolved nitrogen (TDN) values exceeded total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error.} \usage{ -qcChemTDN( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemTDN(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcChemTDP.Rd b/man/qcChemTDP.Rd index e3dbfb2..0bd5d62 100644 --- a/man/qcChemTDP.Rd +++ b/man/qcChemTDP.Rd @@ -4,26 +4,19 @@ \alias{qcChemTDP} \title{List all routine samples where total dissolved phosphorous (TDP) values exceeded total phosphorus (UTP) values, and flag whether the discrepancy was within precision limits or outside of the expected error.} \usage{ -qcChemTDP( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcChemTDP(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcClosureErrorDiscrepancies.Rd b/man/qcClosureErrorDiscrepancies.Rd index a6b0d74..5d70ded 100644 --- a/man/qcClosureErrorDiscrepancies.Rd +++ b/man/qcClosureErrorDiscrepancies.Rd @@ -4,26 +4,19 @@ \alias{qcClosureErrorDiscrepancies} \title{Check the difference between closure errors calculated in R with those calculated in the Survey123 app} \usage{ -qcClosureErrorDiscrepancies( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcClosureErrorDiscrepancies(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcDPLCheck.Rd b/man/qcDPLCheck.Rd index 12390c4..f785c10 100644 --- a/man/qcDPLCheck.Rd +++ b/man/qcDPLCheck.Rd @@ -4,27 +4,14 @@ \alias{qcDPLCheck} \title{Return list of site visits that have any data categorized as "Raw" or "Provisional"} \usage{ -qcDPLCheck( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcDPLCheck(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns SiteCode, SiteName, VisitDate, FieldSeason, SampleFrame, VisitType, Visit.DPL, Chem.DPL, BMI.DPL, Channel.DPL, Clarity.DPL, LakeSurvey.DPL, LakeString.DPL, Xsection.DPL, TempC.DPL, pH.DPL, SpCond.DPL, DO.DPL diff --git a/man/qcElevationDiscrepancies.Rd b/man/qcElevationDiscrepancies.Rd index 9c3362f..de214e7 100644 --- a/man/qcElevationDiscrepancies.Rd +++ b/man/qcElevationDiscrepancies.Rd @@ -4,26 +4,19 @@ \alias{qcElevationDiscrepancies} \title{Check the difference between benchmark and water surface elevations calculated in R with those calculated in the Survey123 app} \usage{ -qcElevationDiscrepancies( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcElevationDiscrepancies(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcLakeDryMeasurementsExist.Rd b/man/qcLakeDryMeasurementsExist.Rd index 461d03e..29c3b19 100644 --- a/man/qcLakeDryMeasurementsExist.Rd +++ b/man/qcLakeDryMeasurementsExist.Rd @@ -4,26 +4,19 @@ \alias{qcLakeDryMeasurementsExist} \title{List clarity records where lake is dry but clarity measurements exist} \usage{ -qcLakeDryMeasurementsExist( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcLakeDryMeasurementsExist(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcLakeNotDryMeasurementsMissing.Rd b/man/qcLakeNotDryMeasurementsMissing.Rd index 2310076..f7d1a92 100644 --- a/man/qcLakeNotDryMeasurementsMissing.Rd +++ b/man/qcLakeNotDryMeasurementsMissing.Rd @@ -4,26 +4,19 @@ \alias{qcLakeNotDryMeasurementsMissing} \title{List clarity records where lake is not dry but measurements are missing} \usage{ -qcLakeNotDryMeasurementsMissing( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcLakeNotDryMeasurementsMissing(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcLakeWqCleaned.Rd b/man/qcLakeWqCleaned.Rd index 523b56b..142e9d3 100644 --- a/man/qcLakeWqCleaned.Rd +++ b/man/qcLakeWqCleaned.Rd @@ -4,26 +4,19 @@ \alias{qcLakeWqCleaned} \title{Intermediate step used to clean lake water quality data for stats and plotting functions.} \usage{ -qcLakeWqCleaned( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcLakeWqCleaned(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcLakeWqFlags.Rd b/man/qcLakeWqFlags.Rd index 5457ca3..fa30838 100644 --- a/man/qcLakeWqFlags.Rd +++ b/man/qcLakeWqFlags.Rd @@ -4,26 +4,19 @@ \alias{qcLakeWqFlags} \title{Compile list of lake water quality values that have data quality flags.} \usage{ -qcLakeWqFlags( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcLakeWqFlags(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcLakeWqSanity.Rd b/man/qcLakeWqSanity.Rd index ac5d6bb..caadaf0 100644 --- a/man/qcLakeWqSanity.Rd +++ b/man/qcLakeWqSanity.Rd @@ -4,26 +4,19 @@ \alias{qcLakeWqSanity} \title{Lake water quality sanity check} \usage{ -qcLakeWqSanity( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcLakeWqSanity(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcNoAnnualVisit.Rd b/man/qcNoAnnualVisit.Rd index f7850ec..4f0bff3 100644 --- a/man/qcNoAnnualVisit.Rd +++ b/man/qcNoAnnualVisit.Rd @@ -4,27 +4,14 @@ \alias{qcNoAnnualVisit} \title{Return list of streams and lakes that were not visited for annual monitoring during a field season} \usage{ -qcNoAnnualVisit( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcNoAnnualVisit(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, VisitDate diff --git a/man/qcSecchiDepthMissing.Rd b/man/qcSecchiDepthMissing.Rd index f4dbca3..240aaac 100644 --- a/man/qcSecchiDepthMissing.Rd +++ b/man/qcSecchiDepthMissing.Rd @@ -4,26 +4,19 @@ \alias{qcSecchiDepthMissing} \title{List clarity records where secchi disk is not on bottom but secchi depth measurement is missing} \usage{ -qcSecchiDepthMissing( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcSecchiDepthMissing(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcSecchiGTDepth.Rd b/man/qcSecchiGTDepth.Rd index 052cd60..e107b20 100644 --- a/man/qcSecchiGTDepth.Rd +++ b/man/qcSecchiGTDepth.Rd @@ -4,26 +4,19 @@ \alias{qcSecchiGTDepth} \title{List secchi depth measurements that are greater than the recorded lake depth} \usage{ -qcSecchiGTDepth( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcSecchiGTDepth(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcStreamWqCleaned.Rd b/man/qcStreamWqCleaned.Rd index 1e1a80e..ae85056 100644 --- a/man/qcStreamWqCleaned.Rd +++ b/man/qcStreamWqCleaned.Rd @@ -4,26 +4,19 @@ \alias{qcStreamWqCleaned} \title{Intermediate step used to clean stream water quality data for stats and plotting functions.} \usage{ -qcStreamWqCleaned( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcStreamWqCleaned(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcStreamWqFlags.Rd b/man/qcStreamWqFlags.Rd index 0ccb147..c9f85ed 100644 --- a/man/qcStreamWqFlags.Rd +++ b/man/qcStreamWqFlags.Rd @@ -4,26 +4,19 @@ \alias{qcStreamWqFlags} \title{Compile list of stream water quality values that have data quality flags.} \usage{ -qcStreamWqFlags( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcStreamWqFlags(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcStreamWqSanity.Rd b/man/qcStreamWqSanity.Rd index b519161..cf63150 100644 --- a/man/qcStreamWqSanity.Rd +++ b/man/qcStreamWqSanity.Rd @@ -4,26 +4,19 @@ \alias{qcStreamWqSanity} \title{Stream water quality sanity check} \usage{ -qcStreamWqSanity( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcStreamWqSanity(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcStringSurveyElevations.Rd b/man/qcStringSurveyElevations.Rd index fd2c251..ce9d48e 100644 --- a/man/qcStringSurveyElevations.Rd +++ b/man/qcStringSurveyElevations.Rd @@ -4,29 +4,15 @@ \alias{qcStringSurveyElevations} \title{Calculates mean and standard deviation of string survey lake level elevations for each year} \usage{ -qcStringSurveyElevations( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) +qcStringSurveyElevations(park, site, field.season, sd_cutoff = NA) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ diff --git a/man/qcStringSurveyHeights.Rd b/man/qcStringSurveyHeights.Rd index 74a84ef..fcfca84 100644 --- a/man/qcStringSurveyHeights.Rd +++ b/man/qcStringSurveyHeights.Rd @@ -4,29 +4,15 @@ \alias{qcStringSurveyHeights} \title{Calculates mean and standard deviation of string survey heights for each benchmark} \usage{ -qcStringSurveyHeights( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - sd_cutoff = NA -) +qcStringSurveyHeights(park, site, field.season, sd_cutoff = NA) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ diff --git a/man/qcWqCleaned.Rd b/man/qcWqCleaned.Rd index 49a4254..143360f 100644 --- a/man/qcWqCleaned.Rd +++ b/man/qcWqCleaned.Rd @@ -4,30 +4,22 @@ \alias{qcWqCleaned} \title{Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags.} \usage{ -qcWqCleaned( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) +qcWqCleaned(park, site, field.season, wq.type) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} + +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{data.source}{Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. diff --git a/man/qcWqCompleteness.Rd b/man/qcWqCompleteness.Rd index e9db358..ce427a4 100644 --- a/man/qcWqCompleteness.Rd +++ b/man/qcWqCompleteness.Rd @@ -4,26 +4,19 @@ \alias{qcWqCompleteness} \title{Calculate the number and percentage of days of data for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days).} \usage{ -qcWqCompleteness( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcWqCompleteness(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcWqCompletenessPlot.Rd b/man/qcWqCompletenessPlot.Rd index 7e1a6b2..7531008 100644 --- a/man/qcWqCompletenessPlot.Rd +++ b/man/qcWqCompletenessPlot.Rd @@ -4,26 +4,19 @@ \alias{qcWqCompletenessPlot} \title{Plot percent completeness for each water quality parameter for each stream for each field season.} \usage{ -qcWqCompletenessPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcWqCompletenessPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcWqFlags.Rd b/man/qcWqFlags.Rd index 06eec02..8ffb5e4 100644 --- a/man/qcWqFlags.Rd +++ b/man/qcWqFlags.Rd @@ -4,30 +4,22 @@ \alias{qcWqFlags} \title{Compile list of water quality values that have data quality flags.} \usage{ -qcWqFlags( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) +qcWqFlags(park, site, field.season, wq.type) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} + +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. diff --git a/man/qcWqGrades.Rd b/man/qcWqGrades.Rd index a83d58c..4e64b72 100644 --- a/man/qcWqGrades.Rd +++ b/man/qcWqGrades.Rd @@ -4,26 +4,19 @@ \alias{qcWqGrades} \title{Calculate the percentage of data rated at each grade level for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days).} \usage{ -qcWqGrades( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcWqGrades(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcWqGradesLong.Rd b/man/qcWqGradesLong.Rd index 35433bc..f937e24 100644 --- a/man/qcWqGradesLong.Rd +++ b/man/qcWqGradesLong.Rd @@ -4,26 +4,19 @@ \alias{qcWqGradesLong} \title{Calculate percentage of data rated at each grade level for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days). Long format for ease of plotting.} \usage{ -qcWqGradesLong( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcWqGradesLong(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcWqGradesPlot.Rd b/man/qcWqGradesPlot.Rd index 3430ba8..d859fda 100644 --- a/man/qcWqGradesPlot.Rd +++ b/man/qcWqGradesPlot.Rd @@ -4,26 +4,19 @@ \alias{qcWqGradesPlot} \title{Plot the percentage of data rated at each grade level for each water quality parameter for each field season.} \usage{ -qcWqGradesPlot( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +qcWqGradesPlot(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/qcWqSanity.Rd b/man/qcWqSanity.Rd index 0c15942..07b5e8c 100644 --- a/man/qcWqSanity.Rd +++ b/man/qcWqSanity.Rd @@ -4,30 +4,22 @@ \alias{qcWqSanity} \title{Water quality sanity check} \usage{ -qcWqSanity( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database", - wq.type -) +qcWqSanity(park, site, field.season, wq.type) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} - \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} + +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + +\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. From b07568a9214b59e635c432742bf1136baea15a04 Mon Sep 17 00:00:00 2001 From: Bailard Date: Mon, 22 Apr 2024 12:11:20 -0700 Subject: [PATCH 12/27] Created new BMI data wrangling functions, updated BMI summary and visualization functions, updated Roxygen information --- NAMESPACE | 7 +- R/bmi-qc.R | 499 ++++++++++++------------- R/calculations.R | 78 ++-- R/chem-qc.R | 280 ++++++-------- R/clarity-qc.R | 52 +-- R/efficiency-qc.R | 490 +++++++++++------------- R/levels-qc.R | 286 +++++++------- R/utils.R | 43 +-- R/wq-qc.R | 192 ++++------ man/BMIDiversityMetricsPlot.Rd | 6 - man/BMIFormatted.Rd | 10 +- man/BMIFunctionalMetricsPlot.Rd | 6 - man/BMIGeneralMetricsPlot.Rd | 6 - man/BMILong.Rd | 36 -- man/BMIMetricsLong.Rd | 27 ++ man/BMISensitivityMetricsPlot.Rd | 21 ++ man/BMISpecies.Rd | 27 ++ man/BMITaxonomicMetricsPlot.Rd | 6 - man/BMIToleranceMetricsPlot.Rd | 27 -- man/ChannelCharacteristics.Rd | 18 +- man/ChannelFLow.Rd | 20 +- man/ChannelSubstrate.Rd | 12 +- man/ChemANC.Rd | 12 +- man/ChemLakeANCPlot.Rd | 12 +- man/ChemStreamANCPlot.Rd | 12 +- man/GetRawData.Rd | 17 +- man/LakeSurfaceElevation.Rd | 7 +- man/LakeWqMedian.Rd | 8 +- man/PlotBenchmarkElevation.Rd | 6 +- man/PlotLakeSurfaceElevation.Rd | 6 +- man/StreamWqMedian.Rd | 8 +- man/SurveyPointElevation.Rd | 9 +- man/WqDailyMean.Rd | 14 +- man/WqDailyMeanLong.Rd | 8 +- man/WqPlotDODepthProfile.Rd | 2 +- man/WqPlotDepthProfile.Rd | 2 +- man/WqPlotPHDepthProfile.Rd | 8 +- man/WqPlotSpCondDepthProfile.Rd | 8 +- man/qcBMIDiscrepancies.Rd | 20 +- man/qcBenchmarkElevation.Rd | 9 +- man/qcChemFieldBlanks.Rd | 14 +- man/qcChemFieldDupes.Rd | 14 +- man/qcChemFlags.Rd | 14 +- man/qcChemLabDupes.Rd | 14 +- man/qcChemMDL.Rd | 6 +- man/qcChemML.Rd | 12 +- man/qcChemNO3NO2.Rd | 14 +- man/qcChemTDN.Rd | 14 +- man/qcChemTDP.Rd | 14 +- man/qcClosureErrorDiscrepancies.Rd | 15 +- man/qcDPLCheck.Rd | 8 +- man/qcElevationDiscrepancies.Rd | 15 +- man/qcLakeDryMeasurementsExist.Rd | 15 +- man/qcLakeNotDryMeasurementsMissing.Rd | 13 +- man/qcLakeWqCleaned.Rd | 8 +- man/qcLakeWqFlags.Rd | 8 +- man/qcLakeWqSanity.Rd | 8 +- man/qcNoAnnualVisit.Rd | 6 +- man/qcSecchiDepthMissing.Rd | 15 +- man/qcSecchiGTDepth.Rd | 13 +- man/qcStreamWqCleaned.Rd | 8 +- man/qcStreamWqFlags.Rd | 8 +- man/qcStreamWqSanity.Rd | 8 +- man/qcStringSurveyElevations.Rd | 7 +- man/qcStringSurveyHeights.Rd | 9 +- man/qcWqCleaned.Rd | 8 +- man/qcWqCompleteness.Rd | 12 +- man/qcWqCompletenessPlot.Rd | 12 +- man/qcWqFlags.Rd | 8 +- man/qcWqGrades.Rd | 12 +- man/qcWqGradesLong.Rd | 12 +- man/qcWqGradesPlot.Rd | 12 +- man/qcWqSanity.Rd | 8 +- 73 files changed, 1048 insertions(+), 1633 deletions(-) delete mode 100644 man/BMILong.Rd create mode 100644 man/BMIMetricsLong.Rd create mode 100644 man/BMISensitivityMetricsPlot.Rd create mode 100644 man/BMISpecies.Rd delete mode 100644 man/BMIToleranceMetricsPlot.Rd diff --git a/NAMESPACE b/NAMESPACE index 0aecd89..b0284ba 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,11 +4,12 @@ export(BMIDiversityMetricsPlot) export(BMIFormatted) export(BMIFunctionalMetricsPlot) export(BMIGeneralMetricsPlot) -export(BMILong) +export(BMIMetricsLong) +export(BMISensitivityMetricsPlot) +export(BMISpecies) export(BMITaxonomicMetricsPlot) -export(BMIToleranceMetricsPlot) export(ChannelCharacteristics) -export(ChannelFLow) +export(ChannelFlow) export(ChannelSubstrate) export(ChemANC) export(ChemLakeANCPlot) diff --git a/R/bmi-qc.R b/R/bmi-qc.R index f10da38..d8b12aa 100644 --- a/R/bmi-qc.R +++ b/R/bmi-qc.R @@ -1,144 +1,144 @@ -#' Pivot BMI data to long format +#' Return BMI metrics data #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". -#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR1". +#' @param field.season Optional. Field season name to filter on, e.g. "2019". +#' +#' @return A tibble +#' @export +#' +#' @examples +#' \dontrun{ +#' BMIMetricsLong() +#' BMIMetricsLong(site = c("GRBA_S_MILL1", "GRBA_S_Pine1"), field.season = "2015") +#' } +BMIMetricsLong <- function(park, site, field.season) { + metrics <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIMetrics") + visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIVisit") + meta <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") + + meta <- meta |> + dplyr::select(SiteCode, VisitDate, SiteShort, VisitType) |> + unique() + + visit <- visit |> + dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) |> + dplyr::rename(VisitDate = CollectionDate) |> + unique() + + metrics <- metrics |> + dplyr::select(SampleID, Attribute, Value) |> + unique() + + join <- metrics |> + dplyr::left_join(visit, by = "SampleID", relationship = "many-to-one") |> + dplyr::left_join(meta, by = c("SiteCode", "VisitDate"), relationship = "many-to-one") |> + dplyr::select(Laboratory, SampleID, Project, Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount, Attribute, Value) |> + unique() + + return(join) +} + + +#' Return BMI species data +#' +#' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR1". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' c <- OpenDatabaseConnection -#' bmi_long <- BMILong(c) # Pivot all BMI data longer -#' bmi_long_mill <- BMILong(c, site = "GRBA_S_MILL1") # Pivot BMI data from Mill Creek -#' bmi_long_bakr_2015 <- BMILong(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") -#' CloseDatabaseConnection(c) +#' BMISpecies() +#' BMISpecies(site = c("GRBA_S_MILL1", "GRBA_S_Pine1"), field.season = "2015") #' } -BMILong <- function(park, site, field.season) { - bmi <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMI") - # Fix column names (will eventually be fixed in db and we can get rid of this code) - if ("PlecopteraTaxa" %in% names(bmi)) { - bmi %<>% dplyr::rename(PlecopteraTaxaCount = PlecopteraTaxa) - } - if ("LongLivedTaxa" %in% names(bmi)) { - bmi %<>% dplyr::rename(LongLivedTaxaCount = LongLivedTaxa) - } - if ("Richness" %in% names(bmi)) { - bmi %<>% dplyr::rename(TotalCount = Richness) - } - if ("Abundance" %in% names(bmi)) { - bmi %<>% dplyr::rename(TotalAbundance = Abundance) - } - if ("DominantTaxa" %in% names(bmi)) { - bmi %<>% dplyr::rename(DominantTaxon = DominantTaxa) - } - if ("DominantTaxaAbundance" %in% names(bmi)) { - bmi %<>% dplyr::rename(DominantTaxonAbundance = DominantTaxaAbundance) - } - if ("DominantTaxaPercent" %in% names(bmi)) { - bmi %<>% dplyr::rename(DominantTaxonPercent = DominantTaxaPercent) - } - if (!("ClingerAbundance" %in% names (bmi))) { - bmi %<>% dplyr::mutate(ClingerAbundance = NA) %>% - dplyr::relocate(ClingerAbundance, .after = ClingerTaxaCount) - } - if (!("LongLivedAbundance" %in% names (bmi))) { - bmi %<>% dplyr::mutate(LongLivedAbundance = NA) %>% - dplyr::relocate(LongLivedAbundance, .after = LongLivedTaxaCount) - } - if (!("DominantTaxonCount" %in% names (bmi))) { - bmi %<>% dplyr::mutate(DominantTaxonCount = NA) - } - if (!("DominantFamilyCount" %in% names (bmi))) { - bmi %<>% dplyr::mutate(DominantFamilyCount = NA) - } - - bmi %<>% dplyr::mutate(DominantFamilyPercent = DominantFamilyAbundance/TotalAbundance*100) - - count_cols <- "^(?!(Split|Fixed|BigRare)).+Count$" # Regex for selecting count columns - abundance_cols <- "^.+Abundance$" # Regex for selecting abundance columns - - count_pivot <- bmi %>% - dplyr::select(!tidyselect::matches(abundance_cols, perl = TRUE)) %>% - tidyr::pivot_longer(tidyselect::matches(count_cols, perl = TRUE), names_to = "TaxaGroup", values_to = "TaxaGroupRichness") %>% - dplyr::mutate(TaxaGroup = gsub("Count", "", TaxaGroup), - TaxaGroup = gsub("Taxa", "", TaxaGroup)) - - abundance_pivot <- bmi %>% - dplyr::select(!tidyselect::matches(count_cols, perl = TRUE)) %>% - tidyr::pivot_longer(tidyselect::matches(abundance_cols, perl = TRUE), names_to = "TaxaGroup", values_to = "TaxaGroupDensity") %>% - dplyr::mutate(TaxaGroup = gsub("Abundance", "", TaxaGroup), - TaxaGroup = gsub("Taxa", "", TaxaGroup)) - - bmi_long <- dplyr::inner_join(count_pivot, abundance_pivot, by = c("Park", "SiteShort", "SiteCode", "SiteName", "FieldSeason", "VisitDate", "VisitType", "SampleType", "SampleCollectionMethod", "DPL", "BMIMethod", "LabSampleNumber", "DateCollected", "LabNotes", "FieldNotes", "SampleArea_m2", "FieldSplit", "LabSplit", "SplitCount", "FixedCount", "BigRareCount", "ShannonsDiversity", "SimpsonsDiversity", "Hilsenhoff", "Evenness", "USFSCommunityToleranceQuo", "DominantFamily", "DominantFamilyPercent", "DominantTaxon", "LabName", "TaxaGroup")) - - # Throw error if join gets messed up somehow - if ((nrow(bmi_long) != nrow(count_pivot)) | (nrow(bmi_long) != nrow(abundance_pivot))) { - stop(paste("Something went wrong when pivoting BMI data. There are", nrow(count_pivot), "rows of count data,", nrow(abundance_pivot), "rows of abundance data, and joining them yields", nrow(bmi_long), "rows of data.")) - } - - return(bmi_long) +BMISpecies <- function(park, site, field.season) { + species <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMISpecies") + visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIVisit") + + visit <- visit |> + dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) + + filtered <- species |> + dplyr::rename(Order = Order_) |> + dplyr::filter(!(Phylum %in% c("Chordata"))) |> + dplyr::mutate(Phylum = dplyr::case_when((Class =="Malacostraca") & (is.na(Phylum)) ~ "Arthropoda", + (Class == "Branchiopoda") & (is.na(Phylum)) ~ "Arthropoda", + (ScientificName == "Nematoda") & (is.na(Phylum)) ~ "Nematoda", + (ScientificName == "Platyhelminthes") & (is.na(Phylum)) ~ "Platyhelminthes", + (ScientificName == "Xenacoelomorpha") & (is.na(Phylum)) ~ "Xenacoelomorpha", + (ScientificName == "Oligochaeta") & (is.na(Phylum)) ~ "Annelida", + TRUE ~ Phylum), + Class = dplyr::case_when((ScientificName == "Oligochaeta") & (is.na(Class)) ~ "Clitellata", + (ScientificName == "Collembola") & (is.na(Class)) ~ "Entognatha", + TRUE ~ Class)) |> + dplyr::select(SampleID, Phylum, Class, Order, Family, SubFamily, Genus, Species, ScientificName, OTUName, LifeStage, Notes, LabCount, BigRareCount) + + join <- filtered |> + dplyr::left_join(visit, by = "SampleID", relationship = "many-to-many") |> + dplyr::select(Laboratory, SampleID, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount, Phylum, Class, Order, Family, SubFamily, Genus, Species, ScientificName, OTUName, LifeStage, Notes, LabCount, BigRareCount) + + return(join) } -#' Check for discrepancies between taxa count and abundance + +#' BROKEN! FIX! Check for discrepancies between taxa count and abundance #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupCount, TaxaGroupAbundance, LabNotes. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' c <- OpenDatabaseConnection -#' bmi_issues <- qcBMIDiscrepancies(c) # Get all instances of discrepancy between taxa count and abundance -#' bmi_issues_mill <- qcBMIDiscrepancies(c, site = "GRBA_S_MILL1") # Look at issues for Mill Creek only -#' bmi_issues_bakr_2015 <- qcBMIDiscrepancies(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") # Look at issues for Baker Creek sites in 2015 -#' CloseDatabaseConnection(c) +#' qcBMIDiscrepancies() +#' qcBMIDiscrepancies(site = "GRBA_S_MILL1") +#' qcBMIDiscrepancies(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") #' } qcBMIDiscrepancies <- function(park, site, field.season) { - bmi_issues <- BMILong(park = park, site = site, field.season = field.season) %>% - dplyr::select(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupRichness, TaxaGroupDensity, LabNotes) %>% + import <- BMIFormatted(park = park, site = site, field.season = field.season) + + bmi_issues <- import |> + dplyr::filter(Metric %in% c("Richness", "Density")) |> + dplyr::mutate(Pivot = dplyr::case_when(Category %in% c("Overall") ~ paste0(Category), + TRUE ~ paste0(Type))) |> + dplyr::select(Park, SiteShort, SiteCode, SiteName, CollectionDate, FieldSeason, Metric, Pivot, Value) |> + tidyr::pivot_wider(names_from = Pivot, values_from = Value) dplyr::filter((TaxaGroupRichness == 0 & TaxaGroupDensity > 0) | (TaxaGroupDensity == 0 & TaxaGroupRichness > 0)) return(bmi_issues) } -#' Filter channel characteristic data by primary visit type +#' Return a table of channel characteristics data #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, Transect, TransectSide, ChannelType, Substrate, Notes +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection -#' channel <- ChannelCharacteristics(conn) -#' channel_STRW2_2016 <- ChannelCharacteristics(conn, site = "GRBA_S_STRW2", field.season = "2016") -#' CloseDatabaseConnection(conn) +#' channel <- ChannelCharacteristics() +#' channel <- ChannelCharacteristics(site = "GRBA_S_STRW2", field.season = "2016") #' } ChannelCharacteristics <- function(park, site, field.season) { - data <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Channel") + channel <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Channel") visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") - channel_characteristics <- dplyr::left_join(data, visit[, c("Park", "SiteShort", "SiteCode", "SiteName", "FieldSeason", "VisitDate", "VisitType")], by = c("Park", "SiteShort", "SiteCode", "SiteName", "FieldSeason", "VisitDate")) %>% - dplyr::filter(VisitType == "Primary") %>% - dplyr::select(-c(DPL, VisitType)) %>% + visit <- visit |> + dplyr::select(SiteCode, VisitDate, VisitType) + + channel_characteristics <- channel |> + dplyr::left_join(visit, by = c("SiteCode", "VisitDate")) |> + dplyr::filter(VisitType == "Primary")|> + dplyr::select(-c(DPL, VisitType)) |> dplyr::arrange(SiteCode, VisitDate, Transect) return(channel_characteristics) @@ -146,31 +146,28 @@ ChannelCharacteristics <- function(park, site, field.season) { #' Rank channel flow type by count for each BMI sample #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelFlow, Rank, Count +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection -#' channel_flow <- ChannelFlow(conn) -#' channel_flow_STRW2_2016 <- ChannelFlow(conn, site = "GRBA_S_STRW2", field.season = "2016") -#' CloseDatabaseConnection(conn) +#' ChannelFlow() +#' ChannelFlow(site = "GRBA_S_STRW2", field.season = "2016") #' } -ChannelFLow <- function(park, site, field.season) { - channel_flow <- ChannelCharacteristics(park = park, site = site, field.season = field.season) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelType) %>% - dplyr::summarize(Count = n()) %>% - dplyr::mutate(Rank = min_rank(desc(Count))) %>% - dplyr::relocate(Count, .after = Rank) %>% - dplyr::rename(ChannelFLow = ChannelType) %>% - dplyr::arrange(SiteCode, VisitDate, Rank) %>% +ChannelFlow <- function(park, site, field.season) { + flow <- ChannelCharacteristics(park = park, site = site, field.season = field.season) + + channel_flow <- flow |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelType) |> + dplyr::summarize(Count = dplyr::n()) |> + dplyr::mutate(Rank = dplyr::min_rank(dplyr::desc(Count))) |> + dplyr::relocate(Count, .after = Rank) |> + dplyr::rename(ChannelFlow = ChannelType) |> + dplyr::arrange(SiteCode, VisitDate, Rank) |> dplyr::ungroup() return(channel_flow) @@ -178,73 +175,113 @@ ChannelFLow <- function(park, site, field.season) { #' Rank channel substrate type by count for each BMI sample #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelFlow, Rank, Count #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection -#' channel_substrate <- ChannelSubstrate(conn) -#' channel_substrate_STRW2_2016 <- ChannelSubstrate(conn, site = "GRBA_S_STRW2", field.season = "2016") -#' CloseDatabaseConnection(conn) +#' ChannelSubstrate() +#' ChannelSubstrate(site = "GRBA_S_STRW2", field.season = "2016") #' } ChannelSubstrate <- function(park, site, field.season) { - channel_substrate <- ChannelCharacteristics(park = park, site = site, field.season = field.season) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, Substrate) %>% - dplyr::summarize(Count = n()) %>% - dplyr::mutate(Rank = min_rank(desc(Count))) %>% - dplyr::relocate(Count, .after = Rank) %>% - dplyr::arrange(SiteCode, VisitDate, Rank) %>% + substrate <- ChannelCharacteristics(park = park, site = site, field.season = field.season) + + channel_substrate <- substrate |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, Substrate) |> + dplyr::summarize(Count = dplyr::n()) |> + dplyr::mutate(Rank = dplyr::min_rank(dplyr::desc(Count))) |> + dplyr::relocate(Count, .after = Rank) |> + dplyr::arrange(SiteCode, VisitDate, Rank) |> dplyr::ungroup() return(channel_substrate) } -#' Intermediate step used to pivot BMI data to an even longer format for ease of plotting +#' Create additional filtering and labeling columns for ease of plotting #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble #' @export #' BMIFormatted <- function(park, site, field.season) { - bmi_long <- BMILong(park = park, site = site, field.season = field.season) - - bmi_formatted <- bmi_long %>% - tidyr::pivot_longer(cols = c("TaxaGroupRichness", "TaxaGroupDensity"), names_to = "Metric", values_to = "Count") - - bmi_formatted$Metric[bmi_formatted$Metric == "TaxaGroupRichness"] <- "Richness" - bmi_formatted$Metric[bmi_formatted$Metric == "TaxaGroupDensity"] <- "Density" - - bmi_formatted$TaxaGroupMetric <- paste(bmi_formatted$TaxaGroup, bmi_formatted$Metric, sep = " ") - - bmi_formatted %<>% dplyr::relocate(TaxaGroupMetric, .before = Count) - - return(bmi_formatted) + bmi.long <- BMIMetricsLong(park = park, site = site, field.season = field.season) + + bmi.formatted <- bmi.long |> + dplyr::mutate(Metric = dplyr::case_when(grepl("Richness", Attribute) ~ "Richness", + grepl("Density", Attribute) ~ "Density", + grepl("Hilsenhoff|Shannons|Simpsons|Evenness", Attribute) ~ "Index", + grepl("DominantFamily", Attribute) ~ "Fraction", + grepl("DominantTaxon", Attribute) ~ "Fraction", + TRUE ~ as.character(Attribute))) |> + dplyr::mutate(Category = dplyr::case_when(Attribute %in% c("UniqueRichness") ~ "Overall", + Attribute %in% c("Density") ~ "Overall", + grepl("Feed", Attribute) ~ "Functional Feeding Group", + grepl("Habit", Attribute) ~ "Habitat", + grepl("LongLived|Intolerant|Tolerant", Attribute) ~ "Sensitivity", + grepl("Insecta|Ephemeroptera|Plecoptera|Trichoptera|Coleoptera|Elmidae|Diptera|Chironomidae|Megaloptera|Crustacea|NonInsects|Oligochaeta|Mollusca", Attribute) ~ "Taxa Group", + grepl("DominantFamily", Attribute) ~ "Dominant Family", + grepl("DominantTaxon", Attribute) ~ "Dominant Taxon", + grepl("Hilsenhoff", Attribute) ~ "Hilsenhoff", + grepl("Shannons", Attribute) ~ "Shannons", + grepl("Simpsons", Attribute) ~ "Simpsons", + grepl("Evenness", Attribute) ~ "Evenness", + TRUE ~ as.character(Attribute))) |> + dplyr::mutate(Type = dplyr::case_when(grepl("CollectorFilterer", Attribute) ~ "Collector Filterer", + grepl("CollectorGatherer", Attribute) ~ "Collector Gatherer", + grepl("Scraper", Attribute) ~ "Scraper", + grepl("Shredder", Attribute) ~ "Shredder", + grepl("Parasite", Attribute) ~ "Parasite", + grepl("Predator", Attribute) ~ "Predator", + grepl("PiercerHerbivore", Attribute) ~ "Piercer Herbivore", + grepl("Clinger", Attribute) ~ "Clinger", + grepl("Planktonic", Attribute) ~ "Planktonic", + grepl("Skater", Attribute) ~ "Skater", + grepl("Climber", Attribute) ~ "Climber", + grepl("Crawler", Attribute) ~ "Crawler", + grepl("Swimmer", Attribute) ~ "Swimmer", + grepl("Burrower", Attribute) ~ "Burrower", + grepl("Sprawler", Attribute) ~ "Sprawler", + grepl("LongLived", Attribute) ~ "Long Lived", + grepl("Intolerant", Attribute) ~ "Intolerant", + grepl("Tolerant", Attribute) ~ "Tolerant", + grepl("Insecta", Attribute) ~ "Insecta", + grepl("Ephemeroptera", Attribute) ~ "Ephemeroptera", + grepl("Plecoptera", Attribute) ~ "Plecoptera", + grepl("Trichoptera", Attribute) ~ "Trichoptera", + grepl("Coleoptera", Attribute) ~ "Coleoptera", + grepl("Elmidae", Attribute) ~ "Elmidae", + grepl("Diptera", Attribute) ~ "Diptera", + grepl("Chironomidae", Attribute) ~ "Chironomidae", + grepl("Megaloptera", Attribute) ~ "Megaloptera", + grepl("Crustacea", Attribute) ~ "Crustacea", + grepl("NonInsects", Attribute) ~ "NonInsects", + grepl("Oligochaeta", Attribute) ~ "Oligochaeta", + grepl("Mollusca", Attribute) ~ "Mollusca", + TRUE ~ NA_character_)) |> + dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habitat", "Sensitivity") ~ paste0(Category, ": ", Type), + Category %in% c("Taxa Group") ~ paste0(Category, ": ", Type), + Category %in% c("Overall") ~ paste0(Category, " ", Metric), + Metric %in% c("Index") ~ paste0(Metric, ": ", Category), + Metric %in% c("Fraction") ~ paste0(Metric, ": ", Category), + TRUE ~ NA_character_)) + + return(bmi.formatted) } #' Plot overall richness and abundance metrics for each BMI sample. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export @@ -252,20 +289,20 @@ BMIFormatted <- function(park, site, field.season) { BMIGeneralMetricsPlot <- function(park, site, field.season) { bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) - bmi.gen <- bmi.formatted %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", - TaxaGroup %in% c("Total", "DominantFamily")) + bmi.gen <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteCode != "GRBA_S_BAKR2", + Category %in% c("Overall", "Dominant Family", "Dominant Taxon")) - bmi.gen$Metric_f = factor(bmi.gen$Metric, levels = c("Richness", "Density")) - bmi.gen$TaxaGroup_f = factor(bmi.gen$TaxaGroup, levels = c("Total", "DominantFamily")) + bmi.gen$Metric_f = factor(bmi.gen$Metric, levels = c("Richness", "Density", "Fraction")) + bmi.gen$Category_f = factor(bmi.gen$Category, levels = c("Overall", "Dominant Family", "Dominant Taxon")) bmi.gen.plot <- ggplot2::ggplot(bmi.gen, ggplot2::aes(x = FieldSeason, - y = Count, - group = TaxaGroup, - color = TaxaGroup_f, + y = Value, + group = Category_f, + color = Category_f, text = paste0("Field Season: ", FieldSeason, "
", - "Count: ", Count, "
", - "Taxa Group: ", TaxaGroup_f))) + + "Count: ", Value, "
", + "Category: ", Category_f))) + ggplot2::geom_point() + ggplot2::geom_line(linewidth = 1) + ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + @@ -284,12 +321,9 @@ BMIGeneralMetricsPlot <- function(park, site, field.season) { #' Plot diversity-related metrics and indices for each BMI sample. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export @@ -297,25 +331,21 @@ BMIGeneralMetricsPlot <- function(park, site, field.season) { BMIDiversityMetricsPlot <- function(park, site, field.season) { bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) - bmi.div <- bmi.formatted %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2") %>% - dplyr::select(-c("TaxaGroup", "Metric", "TaxaGroupMetric", "Count")) %>% - dplyr::distinct() %>% - tidyr::pivot_longer(cols = c("ShannonsDiversity", "SimpsonsDiversity", "Evenness", "Hilsenhoff"), names_to = "Metric", values_to = "Value") - - bmi.div$Metric[bmi.div$Metric == "Hilsenhoff"] <- "HilsenhoffIndex" + bmi.div <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", + Metric == "Index") - bmi.div$Metric_f = factor(bmi.div$Metric, levels = c("ShannonsDiversity", "SimpsonsDiversity", "Evenness", "HilsenhoffIndex")) + bmi.div$Category_f = factor(bmi.div$Category, levels = c("Shannons", "Simpsons", "Evenness", "Hilsenhoff")) bmi.div.plot <- ggplot2::ggplot(bmi.div, ggplot2::aes(x = FieldSeason, y = Value, - group = Metric, + group = Category_f, text = paste0("Field Season: ", FieldSeason, "
", "Value: ", Value, "
", - "Metric: ", Metric_f))) + + "Metric: ", Category_f))) + ggplot2::geom_point() + ggplot2::geom_line(linewidth = 1) + - ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + + ggplot2::facet_grid(Category_f~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Value") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + ggplot2::labs(title = "BMI diversity metrics") + @@ -329,39 +359,36 @@ BMIDiversityMetricsPlot <- function(park, site, field.season) { #' Plot tolerance-related richness and abundance metrics for each BMI sample. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export #' -BMIToleranceMetricsPlot <- function(park, site, field.season) { +BMISensitivityMetricsPlot <- function(park, site, field.season) { bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) - bmi.tol <- bmi.formatted %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", - TaxaGroup %in% c("EPT", "Tolerant", "Intolerant", "LongLived", "Clinger")) + bmi.tol <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", + Category %in% c("Sensitivity")) bmi.tol$Metric_f = factor(bmi.tol$Metric, levels = c("Richness", "Density")) - bmi.tol$TaxaGroup_f = factor(bmi.tol$TaxaGroup, levels = c("EPT", "Tolerant", "Intolerant", "LongLived", "Clinger")) + bmi.tol$Type_f = factor(bmi.tol$Type, levels = c("Tolerant", "Intolerant", "Long Lived")) bmi.tol.plot <- ggplot2::ggplot(bmi.tol, ggplot2::aes(x = FieldSeason, - y = Count, - color = TaxaGroup_f, + y = Value, + color = Type_f, text = paste0("Field Season: ", FieldSeason, "
", - "Count: ", Count, "
", - "Taxa Group: ", TaxaGroup_f))) + + "Count: ", Value, "
", + "Sensitivity: ", Type_f))) + ggplot2::geom_point() + - ggplot2::geom_line(ggplot2::aes(group = TaxaGroup), + ggplot2::geom_line(ggplot2::aes(group = Type_f), linewidth = 1) + ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Count") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") + - ggplot2::labs(title = "BMI tolerance metrics", color = "Tolerance Group") + + ggplot2::labs(title = "BMI sensitivity metrics", color = "Sensitivity Group") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + khroma::scale_color_muted() @@ -373,12 +400,9 @@ BMIToleranceMetricsPlot <- function(park, site, field.season) { #' Plot functional feeding group-related richness and abundance metrics for each BMI sample. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export @@ -386,21 +410,21 @@ BMIToleranceMetricsPlot <- function(park, site, field.season) { BMIFunctionalMetricsPlot <- function(park, site, field.season) { bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) - bmi.fun <- bmi.formatted %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", - TaxaGroup %in% c("Shredder", "Scraper", "CollectorFilterer", "CollectorGatherer", "Predator")) + bmi.fun <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", + Category %in% c("Functional Feeding Group")) bmi.fun$Metric_f = factor(bmi.fun$Metric, levels = c("Richness", "Density")) - bmi.fun$TaxaGroup_f = factor(bmi.fun$TaxaGroup, levels = c("Shredder", "Scraper", "CollectorFilterer", "CollectorGatherer", "Predator")) + bmi.fun$Type_f = factor(bmi.fun$Type, levels = c("Collector Filterer", "Collector Gatherer", "Parasite", "Piercer Herbivore", "Predator", "Scraper", "Shredder")) bmi.fun.plot <- ggplot2::ggplot(bmi.fun, ggplot2::aes(x = FieldSeason, - y = Count, - color = TaxaGroup_f, + y = Value, + color = Type_f, text = paste0("Field Season: ", FieldSeason, "
", - "Count: ", Count, "
", - "Taxa Group: ", TaxaGroup_f))) + + "Count: ", Value, "
", + "Functional Feeding Group: ", Type_f))) + ggplot2::geom_point() + - ggplot2::geom_line(ggplot2::aes(group = TaxaGroup), + ggplot2::geom_line(ggplot2::aes(group = Type), linewidth = 1) + ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Count") + @@ -417,12 +441,9 @@ BMIFunctionalMetricsPlot <- function(park, site, field.season) { #' Plot taxonomic-related richness and abundance metrics for each BMI sample. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export @@ -430,25 +451,21 @@ BMIFunctionalMetricsPlot <- function(park, site, field.season) { BMITaxonomicMetricsPlot <- function(park, site, field.season) { bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) - bmi.tax <- bmi.formatted %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", - TaxaGroup %in% c("Insect", "Coleoptera", "Diptera", "Ephemeroptera", "Megaloptera", "Plecoptera","Trichoptera", "Chironomidae", "Elmidae", "NonInsect", "Mollusca", "Crustacea", "Oligochaete")) %>% - dplyr::mutate(TaxaGroup = dplyr::case_when(TaxaGroup == "Insect" ~ "Insecta", - TaxaGroup == "NonInsect" ~ "NonInsecta", - TaxaGroup == "Oligochaete" ~ "Oligochaeta", - TRUE ~ TaxaGroup)) + bmi.tax <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", + Category %in% c("Taxa Group")) bmi.tax$Metric_f = factor(bmi.tax$Metric, levels = c("Richness", "Density")) - bmi.tax$TaxaGroup_f = factor(bmi.tax$TaxaGroup, levels = c("Insecta", "Coleoptera", "Diptera", "Ephemeroptera", "Megaloptera", "Plecoptera", "Trichoptera", "Chironomidae", "Elmidae", "NonInsecta", "Mollusca", "Crustacea", "Oligochaeta")) + bmi.tax$Type_f = factor(bmi.tax$Type, levels = c("Insecta", "Coleoptera", "Diptera", "Ephemeroptera", "Megaloptera", "Plecoptera", "Trichoptera", "Chironomidae", "Elmidae", "Crustacea", "Mollusca", "Oligochaeta", "NonInsects")) bmi.tax.plot <- ggplot2::ggplot(bmi.tax, ggplot2::aes(x = FieldSeason, - y = Count, - color = TaxaGroup_f, + y = Value, + color = Type_f, text = paste0("Field Season: ", FieldSeason, "
", - "Count: ", Count, "
", - "Taxa Group: ", TaxaGroup_f))) + + "Count: ", Value, "
", + "Taxa Group: ", Type_f))) + ggplot2::geom_point() + - ggplot2::geom_line(ggplot2::aes(group = TaxaGroup), + ggplot2::geom_line(ggplot2::aes(group = Type), linewidth = 1) + ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Count") + @@ -461,57 +478,3 @@ BMITaxonomicMetricsPlot <- function(park, site, field.season) { return(bmi.tax.plot) } - - -################################# - -# bmi.div.plot <- ggplot2::ggplot(bmi.div, aes(x = FieldSeason, y = Value, group = Metric, color = Metric)) + -# geom_point() + -# geom_line() + -# facet_grid(~SiteShort, scales = "free_y") + -# ylab(label = "Value") + -# theme(axis.text.x = element_text(angle = 90), legend.position = "bottom") + -# labs(title = "BMI diversity metrics") - -############################################ - -#bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) - -#bmi.tol <- bmi.formatted %>% -# dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", -# TaxaGroup %in% c("EPT", "Tolerant", "Intolerant", "LongLived"), -# TaxaGroupMetric != "LongLived Abundance") - -#bmi.tol$Metric_f = factor(bmi.tol$Metric, levels = c("Richness", "Abundance")) -#bmi.tol$TaxaGroup_f = factor(bmi.tol$TaxaGroup, levels = c("EPT", "Tolerant", "Intolerant", "LongLived")) -#bmi.tol$TaxaGroupMetric_f = factor(bmi.tol$TaxaGroupMetric, levels = c("EPT Richness", "Tolerant Richness", "Intolerant Richness", "LongLived Richness", "EPT Abundance", "Tolerant Abundance", "Intolerant Abundance")) - -#bmi.tol.plot <- ggplot2::ggplot(bmi.tol, aes(x = FieldSeason, y = Amount, color = Metric)) + -# geom_point() + -# geom_line(aes(group = TaxaGroup)) + -# facet_grid(Metric_f+TaxaGroup_f~SiteShort, scales = "free_y") + -# ylab(label = "Count") + -# theme(axis.text.x = element_text(angle = 90)) + -# labs(title = "BMI tolerance metrics") + -# theme(legend.position = "none") - -########################################### - -#bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source) - -#bmi.tax <- bmi.formatted %>% -# dplyr::filter(SampleType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", -# TaxaGroup %in% c("Insect", "Coleoptera", "Diptera", "Ephemeroptera", "Megaloptera", "Plecoptera","Tricoptera", "Chironomidae", "Elmidae", "NonInsect", "Mollusca", "Crustacea", "Oligochaete")) - -#bmi.tax$Metric_f = factor(bmi.tax$Metric, levels = c("Richness", "Abundance")) -#bmi.tax$TaxaGroup_f = factor(bmi.tax$TaxaGroup, levels = c("Insect", "Coleoptera", "Diptera", "Ephemeroptera", "Megaloptera", "Plecoptera","Tricoptera", "Chironomidae", "Elmidae", "NonInsect", "Mollusca", "Crustacea", "Oligochaete")) -#bmi.tax$TaxaGroupMetric_f = factor(bmi.tax$TaxaGroupMetric, levels = c("Insect Richness", "Insect Abundance", "Coleoptera Richness", "Coleoptera Abundance", "Diptera Richness", "Diptera Abundance", "Ephemeroptera Richness", "Ephemeroptera Abundance", "Plecoptera Richness", "Plecoptera Abundance", "Megaloptera Richness", "Megaloptera Abundance", "Tricoptera Richness", "Tricoptera Abundance", "Chironomidae Richness", "Chironomidae Abundance", "Elmidae Richness", "Elmidae Abundance", "NonInsect Richness", "NonInsect Abundance", "Mollusca Richness", "Mollusca Abundance", "Crustacea Richness", "Crustacea Abundance", "Oligochaete Richness", "Oligochaete Abundance")) - -#bmi.tax.plot <- ggplot2::ggplot(bmi.tax, aes(x = FieldSeason, y = Amount, color = Metric)) + -# geom_point() + -# geom_line(aes(group = TaxaGroup)) + -# facet_grid(Metric_f+TaxaGroup_f~SiteShort, scales = "free_y") + -# ylab(label = "Count") + -# theme(axis.text.x = element_text(angle = 90)) + -# labs(title = "BMI taxonomic group metrics") + -# theme(legend.position = "none") diff --git a/R/calculations.R b/R/calculations.R index a43d738..c913f96 100644 --- a/R/calculations.R +++ b/R/calculations.R @@ -25,14 +25,11 @@ MaxDQF <- function(flags) { #' Calculate median values for each water quality parameter for each lake visit. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. +#' @return A tibble #' @export #' LakeWqMedian <- function(park, site, field.season) { @@ -43,47 +40,47 @@ LakeWqMedian <- function(park, site, field.season) { wq.visits <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") - temp.med <- temp %>% - dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% - dplyr::filter(MonitoringStatus == "Sampled") %>% - dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) %>% + temp.med <- temp |> + dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) |> + dplyr::filter(MonitoringStatus == "Sampled") |> + dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) |> dplyr::summarise(TemperatureMedian_C = median(WaterTemperature_C, na.rm = TRUE), - TemperatureCount = sum(!is.na(WaterTemperature_C))) %>% - dplyr::rename(TemperatureFlag = Flag) %>% + TemperatureCount = sum(!is.na(WaterTemperature_C))) |> + dplyr::rename(TemperatureFlag = Flag) |> dplyr::arrange(SiteCode, VisitDate) - spcond.med <- spcond %>% - dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% - dplyr::filter(MonitoringStatus == "Sampled") %>% - dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) %>% + spcond.med <- spcond |> + dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) |> + dplyr::filter(MonitoringStatus == "Sampled") |> + dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) |> dplyr::summarise(SpCondMedian_microS_per_cm = median(SpecificConductance_microS_per_cm, na.rm = TRUE), - SpCondCount = sum(!is.na(SpecificConductance_microS_per_cm))) %>% - dplyr::rename(SpCondFlag = Flag) %>% + SpCondCount = sum(!is.na(SpecificConductance_microS_per_cm))) |> + dplyr::rename(SpCondFlag = Flag) |> dplyr::arrange(SiteCode, VisitDate) - ph.med <- ph %>% - dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% - dplyr::filter(MonitoringStatus == "Sampled") %>% - dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) %>% + ph.med <- ph |> + dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) |> + dplyr::filter(MonitoringStatus == "Sampled") |> + dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) |> dplyr::summarise(pHMedian = median(pH, na.rm = TRUE), - pHCount = sum(!is.na(pH))) %>% - dplyr::rename(pHFlag = Flag) %>% + pHCount = sum(!is.na(pH))) |> + dplyr::rename(pHFlag = Flag) |> dplyr::arrange(SiteCode, VisitDate) - do.med <- do %>% - dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% - dplyr::filter(MonitoringStatus == "Sampled") %>% - dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) %>% + do.med <- do |> + dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) |> + dplyr::filter(MonitoringStatus == "Sampled") |> + dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, MeasurementDepth_m, Flag, FlagNote, DPL) |> dplyr::summarise(DOMedian_percent = median(DissolvedOxygen_percent), DOMedian_mg_per_L = median(DissolvedOxygen_mg_per_L), DOPercentCount = sum(!is.na(DissolvedOxygen_percent)), - DOmgLCount = sum(!is.na(DissolvedOxygen_mg_per_L))) %>% - dplyr::rename(DOFlag = Flag) %>% + DOmgLCount = sum(!is.na(DissolvedOxygen_mg_per_L))) |> + dplyr::rename(DOFlag = Flag) |> dplyr::arrange(SiteCode, VisitDate) - wq.med <- temp.med %>% - dplyr::full_join(spcond.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) %>% - dplyr::full_join(ph.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) %>% - dplyr::full_join(do.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) %>% + wq.med <- temp.med |> + dplyr::full_join(spcond.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) |> + dplyr::full_join(ph.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) |> + dplyr::full_join(do.med, by = c("Park", "FieldSeason", "SiteCode", "VisitDate", "VisitType", "SampleFrame", "MeasurementDepth_m", "FlagNote", "DPL")) |> dplyr::ungroup() return(wq.med) @@ -91,24 +88,21 @@ LakeWqMedian <- function(park, site, field.season) { #' Calculate median values for each water quality parameter for each stream visit. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. +#' @return A tibble #' @export #' StreamWqMedian <- function(park, site, field.season) { stream_wq <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WQStreamXSection") wq.visits <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") - stream_wq_med <- stream_wq %>% - dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate, MonitoringStatus), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) %>% - dplyr::filter(MonitoringStatus == "Sampled") %>% - dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, pHFlag, DOFlag, SpCondFlag, TemperatureFlag, FlagNote, DPL) %>% + stream_wq_med <- stream_wq |> + dplyr::left_join(dplyr::select(wq.visits, SampleFrame, Park, FieldSeason, SiteCode, VisitDate, MonitoringStatus), by = c("Park", "FieldSeason", "SiteCode", "VisitDate")) |> + dplyr::filter(MonitoringStatus == "Sampled") |> + dplyr::group_by(Park, FieldSeason, SiteCode, VisitDate, VisitType, SampleFrame, pHFlag, DOFlag, SpCondFlag, TemperatureFlag, FlagNote, DPL) |> dplyr::summarise(TemperatureMedian_C = median(WaterTemperature_C), TemperatureCount = sum(!is.na(WaterTemperature_C)), pHMedian = median(pH), @@ -116,8 +110,8 @@ StreamWqMedian <- function(park, site, field.season) { DOMedian_mg_per_L = median(DissolvedOxygen_mg_per_L), DOmgLCount = sum(!is.na(DissolvedOxygen_mg_per_L)), SpCondMedian_microS_per_cm = median(SpecificConductance_microS_per_cm), - SpCondCount = sum(!is.na(SpecificConductance_microS_per_cm))) %>% - dplyr::arrange(SiteCode, VisitDate) %>% + SpCondCount = sum(!is.na(SpecificConductance_microS_per_cm))) |> + dplyr::arrange(SiteCode, VisitDate) |> dplyr::ungroup() diff --git a/R/chem-qc.R b/R/chem-qc.R index 1088d1e..14638a7 100644 --- a/R/chem-qc.R +++ b/R/chem-qc.R @@ -1,28 +1,23 @@ #' List all laboratory values that have an "Information," "Warning," or "Critical" flag. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemFlags(conn) -#' qcChemFlags(conn, site = c("GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemFlags() +#' qcChemFlags(site = c("GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1"), field.season = c("2018", "2019", "2020")) #' } qcChemFlags <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - flags.list <- chem %>% - dplyr::filter(Flag %in% c("I", "W", "C")) %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote) %>% + flags.list <- chem |> + dplyr::filter(Flag %in% c("I", "W", "C")) |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote) |> dplyr::arrange(SampleFrame, VisitDate, SiteCode) return(flags.list) @@ -32,28 +27,23 @@ return(flags.list) #' Calculate the relative percent difference (RPD) for laboratory duplicates and triplicates, flag results that exceed the 30% MQO threshold, and list all RPD values and flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, LabDuplicate, LabTriplicate, RPD, RPD2, RPDFLag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemLabDupes(conn) -#' qcChemLabDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemLabDupes() +#' qcChemLabDupes(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemLabDupes <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - lab.dupes <- chem %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) %>% + lab.dupes <- chem |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) |> dplyr::filter(SiteCode != "GRBA_L_STLL0s", SampleType %in% c("Routine", "Lab Duplicate", "Lab Triplicate")) lab.dupes.wide <- tidyr::pivot_wider(data = lab.dupes, names_from = SampleType, values_from = LabValue) @@ -78,11 +68,11 @@ qcChemLabDupes <- function(park, site, field.season) { } - lab.dupes.list <- lab.dupes.wide %>% - dplyr::filter(!is.na(LabDuplicate)) %>% - dplyr::mutate(RPD = round(((pmax(Routine, LabDuplicate) - pmin(Routine, LabDuplicate))/((pmax(Routine, LabDuplicate) + pmin(Routine, LabDuplicate))/2))*100, 2)) %>% - dplyr::mutate(RPD2 = round(((pmax(Routine, LabTriplicate) - pmin(Routine, LabTriplicate))/((pmax(Routine, LabTriplicate) + pmin(Routine, LabTriplicate))/2))*100, 2)) %>% - dplyr::mutate(RPDFlag = ifelse(RPD > 30 | RPD2 > 30, "RPD above laboratory precision MQO of 30%", NA)) %>% + lab.dupes.list <- lab.dupes.wide |> + dplyr::filter(!is.na(LabDuplicate)) |> + dplyr::mutate(RPD = round(((pmax(Routine, LabDuplicate) - pmin(Routine, LabDuplicate))/((pmax(Routine, LabDuplicate) + pmin(Routine, LabDuplicate))/2))*100, 2)) |> + dplyr::mutate(RPD2 = round(((pmax(Routine, LabTriplicate) - pmin(Routine, LabTriplicate))/((pmax(Routine, LabTriplicate) + pmin(Routine, LabTriplicate))/2))*100, 2)) |> + dplyr::mutate(RPDFlag = ifelse(RPD > 30 | RPD2 > 30, "RPD above laboratory precision MQO of 30%", NA)) |> dplyr::arrange(desc(RPD)) return(lab.dupes.list) @@ -92,28 +82,23 @@ qcChemLabDupes <- function(park, site, field.season) { #' Calculate the relative percent difference (RPD) for field duplicates, flag results that exceed the 30% MQO threshold, and list all RPD values and flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, FieldDuplicate, RPD, RPDFLag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemFieldDupes(conn) -#' qcChemFieldDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemFieldDupes() +#' qcChemFieldDupes(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemFieldDupes <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - field.dupes <- chem %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) %>% + field.dupes <- chem |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) |> dplyr::filter(SiteCode != "GRBA_L_STLL0s", SampleType %in% c("Routine", "Field Duplicate")) field.dupes.wide <- tidyr::pivot_wider(data = field.dupes, names_from = SampleType, values_from = LabValue) @@ -129,10 +114,10 @@ qcChemFieldDupes <- function(park, site, field.season) { } - field.dupes.list <- field.dupes.wide %>% - dplyr::filter(!is.na(FieldDuplicate)) %>% - dplyr::mutate(RPD = round(((pmax(Routine, FieldDuplicate) - pmin(Routine, FieldDuplicate))/((pmax(Routine, FieldDuplicate) + pmin(Routine, FieldDuplicate))/2))*100, 2)) %>% - dplyr::mutate(RPDFlag = ifelse(RPD > 30, "RPD above laboratory precision MQO of 30%", NA)) %>% + field.dupes.list <- field.dupes.wide |> + dplyr::filter(!is.na(FieldDuplicate)) |> + dplyr::mutate(RPD = round(((pmax(Routine, FieldDuplicate) - pmin(Routine, FieldDuplicate))/((pmax(Routine, FieldDuplicate) + pmin(Routine, FieldDuplicate))/2))*100, 2)) |> + dplyr::mutate(RPDFlag = ifelse(RPD > 30, "RPD above laboratory precision MQO of 30%", NA)) |> dplyr::arrange(desc(RPD)) return(field.dupes.list) @@ -142,30 +127,25 @@ qcChemFieldDupes <- function(park, site, field.season) { #' List all laboratory values from field blanks that exceed the minimum detection level (MDL) for that analyte. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, FieldBlank, RPD, RPDFLag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemFieldBlanks(conn) -#' qcChemFieldBlanks(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemFieldBlanks() +#' qcChemFieldBlanks(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemFieldBlanks <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lookup <- getMDLLookup() - field.blanks <- chem %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) %>% - dplyr::filter(SiteCode != "GRBA_L_STLL0s", SampleType %in% c("Field Blank")) %>% + field.blanks <- chem |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType) |> + dplyr::filter(SiteCode != "GRBA_L_STLL0s", SampleType %in% c("Field Blank")) |> dplyr::mutate(FieldSeason = as.double(FieldSeason)) field.blanks.merged <- fuzzyjoin::fuzzy_inner_join(x = field.blanks, @@ -173,10 +153,10 @@ qcChemFieldBlanks <- function(park, site, field.season) { by = c("Characteristic" = "Characteristic", "Unit" = "Unit", "FieldSeason" = "StartYear", "FieldSeason" = "EndYear"), match_fun = list(`==`, `==`, `>=`, `<=`)) - field.blanks.list <- field.blanks.merged %>% - dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) %>% - dplyr::mutate(FieldSeason = as.character(FieldSeason)) %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, MDL) %>% + field.blanks.list <- field.blanks.merged |> + dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) |> + dplyr::mutate(FieldSeason = as.character(FieldSeason)) |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, MDL) |> dplyr::filter(LabValue > MDL) return(field.blanks.list) @@ -186,36 +166,31 @@ qcChemFieldBlanks <- function(park, site, field.season) { #' List all routine samples where total dissolved nitrogen (TDN) values exceeded total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTN, TDN, TDNvUTN, TDNFlag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemTDN(conn) -#' qcChemTDN(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemTDN() +#' qcChemTDN(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemTDN <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - TDN <- chem %>% - dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) %>% + TDN <- chem |> + dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) |> dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, Unit, LabValue) TDN.wide <- tidyr::pivot_wider(data = TDN, names_from = Characteristic, values_from = LabValue) - TDN.list <- TDN.wide %>% - dplyr::rename(NO3NO2 = `NO3NO2-N`) %>% - dplyr::mutate(TDNvUTN = ifelse(TDN > UTN, round(TDN - UTN, 2), NA)) %>% - dplyr::mutate(TDNFlag = ifelse(TDNvUTN > 0.01, "TDN is greater than UTN outside the normal limits of variability", "TDN is greater than UTN within precision limits")) %>% + TDN.list <- TDN.wide |> + dplyr::rename(NO3NO2 = `NO3NO2-N`) |> + dplyr::mutate(TDNvUTN = ifelse(TDN > UTN, round(TDN - UTN, 2), NA)) |> + dplyr::mutate(TDNFlag = ifelse(TDNvUTN > 0.01, "TDN is greater than UTN outside the normal limits of variability", "TDN is greater than UTN within precision limits")) |> dplyr::filter(!is.na(TDNvUTN)) return(TDN.list) @@ -225,37 +200,32 @@ qcChemTDN <- function(park, site, field.season) { #' List all routine samples where nitrate and nitrite (NO3NO2-N) values exceeded either total dissolved nitrogen (TDN) values or total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTN, TDN, NO3NO2, NO3NO2vUTN, NO3NO2vTDN, NO3NO2Flag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemNO3NO2(conn) -#' qcChemNO3NO2(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemNO3NO2() +#' qcChemNO3NO2(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemNO3NO2 <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - NO3NO2 <- chem %>% - dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) %>% + NO3NO2 <- chem |> + dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTN", "TDN", "NO3NO2-N")) |> dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, Unit, LabValue) NO3NO2.wide <- tidyr::pivot_wider(data = NO3NO2, names_from = Characteristic, values_from = LabValue) - NO3NO2.list <- NO3NO2.wide %>% - dplyr::rename(NO3NO2 = `NO3NO2-N`) %>% - dplyr::mutate(NO3NO2vUTN = ifelse(NO3NO2 > UTN, round(NO3NO2 - UTN, 3), NA)) %>% - dplyr::mutate(NO3NO2vTDN = ifelse(NO3NO2 > TDN, round(NO3NO2 - TDN, 3), NA)) %>% - dplyr::mutate(NO3NO2Flag = ifelse(NO3NO2vUTN > 0.01 | NO3NO2vTDN > 0.01, "NO3NO2 is greater than UTN and/or TDN outside the normal limits of variability", "NO3NO2 is greater than TDN and/or UTN within precision limits")) %>% + NO3NO2.list <- NO3NO2.wide |> + dplyr::rename(NO3NO2 = `NO3NO2-N`) |> + dplyr::mutate(NO3NO2vUTN = ifelse(NO3NO2 > UTN, round(NO3NO2 - UTN, 3), NA)) |> + dplyr::mutate(NO3NO2vTDN = ifelse(NO3NO2 > TDN, round(NO3NO2 - TDN, 3), NA)) |> + dplyr::mutate(NO3NO2Flag = ifelse(NO3NO2vUTN > 0.01 | NO3NO2vTDN > 0.01, "NO3NO2 is greater than UTN and/or TDN outside the normal limits of variability", "NO3NO2 is greater than TDN and/or UTN within precision limits")) |> dplyr::filter(!is.na(NO3NO2vUTN | NO3NO2vTDN)) return(NO3NO2.list) @@ -265,35 +235,30 @@ qcChemNO3NO2 <- function(park, site, field.season) { #' List all routine samples where total dissolved phosphorous (TDP) values exceeded total phosphorus (UTP) values, and flag whether the discrepancy was within precision limits or outside of the expected error. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTP, TDP, TDPvUTP, TDPFlag. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemTDP(conn) -#' qcChemTDP(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemTDP() +#' qcChemTDP(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemTDP <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - TDP <- chem %>% - dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTP", "TDP")) %>% + TDP <- chem |> + dplyr::filter(VisitType == "Primary", SampleType == "Routine", ReportingGroup == "Nutrient", Characteristic %in% c("UTP", "TDP")) |> dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, Unit, LabValue) TDP.wide <- tidyr::pivot_wider(data = TDP, names_from = Characteristic, values_from = LabValue) - TDP.list <- TDP.wide %>% - dplyr::mutate(TDPvUTP = ifelse(TDP>UTP, round(TDP - UTP, 3), NA)) %>% - dplyr::mutate(TDPFlag = ifelse(TDPvUTP > 0.002, "TDP is greater than UTP outside the limits of normal variability", "TDP is greater than UTP within precision limits")) %>% + TDP.list <- TDP.wide |> + dplyr::mutate(TDPvUTP = ifelse(TDP>UTP, round(TDP - UTP, 3), NA)) |> + dplyr::mutate(TDPFlag = ifelse(TDPvUTP > 0.002, "TDP is greater than UTP outside the limits of normal variability", "TDP is greater than UTP within precision limits")) |> dplyr::filter(!is.na(TDPvUTP)) return(TDP.list) @@ -333,17 +298,15 @@ getMDLLookup <- function() { #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemMDL(conn) -#' qcChemMDL(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemMDL() +#' qcChemMDL(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemMDL <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") lookup <- getMDLLookup() - mdl <- chem %>% - dplyr::filter(VisitType == "Primary", SampleType == "Routine") %>% + mdl <- chem |> + dplyr::filter(VisitType == "Primary", SampleType == "Routine") |> dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue) mdl.merged <- fuzzyjoin::fuzzy_inner_join(x = mdl, @@ -351,11 +314,11 @@ qcChemMDL <- function(park, site, field.season) { by = c("Characteristic" = "Characteristic", "Unit" = "Unit", "FieldSeason" = "StartYear", "FieldSeason" = "EndYear"), match_fun = list(`==`, `==`, `>=`, `<=`)) - mdl.list <- mdl.merged %>% - dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, MDL) %>% - dplyr::mutate(MDLFlag = ifelse(LabValue <= MDL, "Value is less than or equal to the minimum detection level (MDL)", NA)) %>% - dplyr::filter(!is.na(MDLFlag)) %>% + mdl.list <- mdl.merged |> + dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, MDL) |> + dplyr::mutate(MDLFlag = ifelse(LabValue <= MDL, "Value is less than or equal to the minimum detection level (MDL)", NA)) |> + dplyr::filter(!is.na(MDLFlag)) |> dplyr::arrange(SampleFrame, VisitDate, SiteCode) return(mdl.list) @@ -365,28 +328,23 @@ qcChemMDL <- function(park, site, field.season) { #' List all routine laboratory values that are less than or equal to the minimum level of quantitation (ML) for that analyte. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, ML, MLFlag. #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcChemML(conn) -#' qcChemML(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcChemML() +#' qcChemML(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) #' } qcChemML <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - ml <- chem %>% - dplyr::filter(VisitType == "Primary", SampleType == "Routine") %>% + ml <- chem |> + dplyr::filter(VisitType == "Primary", SampleType == "Routine") |> dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue) ml.merged <- fuzzyjoin::fuzzy_inner_join(x = ml, @@ -394,11 +352,11 @@ qcChemML <- function(park, site, field.season) { by = c("Characteristic" = "Characteristic", "Unit" = "Unit", "FieldSeason" = "StartYear", "FieldSeason" = "EndYear"), match_fun = list(`==`, `==`, `>=`, `<=`)) - ml.list <- ml.merged %>% - dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) %>% - dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, ML) %>% - dplyr::mutate(MLFlag = ifelse(LabValue <= ML, "Value is less than or equal to the minimum level of quantification (ML)", NA)) %>% - dplyr::filter(!is.na(MLFlag)) %>% + ml.list <- ml.merged |> + dplyr::rename(Characteristic = Characteristic.x, Unit = Unit.x) |> + dplyr::select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, ML) |> + dplyr::mutate(MLFlag = ifelse(LabValue <= ML, "Value is less than or equal to the minimum level of quantification (ML)", NA)) |> + dplyr::filter(!is.na(MLFlag)) |> dplyr::arrange(SampleFrame, VisitDate, SiteCode) return(ml.list) @@ -408,29 +366,24 @@ qcChemML <- function(park, site, field.season) { #' Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, SampleFrame, VisitDate, VisitType, SampleCollectionMethod, Characteristic, CharacteristicLabel, LabValue, ReportingGroup, SampleType, Flag, FlagNote, DPL, Unit #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' ChemANC(conn) -#' ChemANC(conn, site = "GRBA_L_DEAD0", field.season = "2018") -#' CloseDatabaseConnection(conn) +#' ChemANC() +#' ChemANC(site = "GRBA_L_DEAD0", field.season = "2018") #' } ChemANC <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - chem.anc.rows <- chem %>% - dplyr::filter(Characteristic == "ALK2") %>% + chem.anc.rows <- chem |> + dplyr::filter(Characteristic == "ALK2") |> dplyr::mutate(Characteristic = "ANC", CharacteristicLabel = "Acid neutralizing capacity", Unit = "ueq/L", @@ -440,8 +393,9 @@ ChemANC <- function(park, site, field.season) { chem.anc <- rbind(chem, chem.anc.rows) - chem.anc %<>% dplyr::arrange(SiteCode, VisitDate, Characteristic) %>% - dplyr::relocate(Unit, .before = "LabValue") + chem.anc <- chem.anc |> + dplyr::arrange(SiteCode, VisitDate, Characteristic) |> + dplyr::relocate(Unit, .before = "LabValue") return(chem.anc) @@ -449,29 +403,24 @@ ChemANC <- function(park, site, field.season) { #' Plot acid neutralizing capacity (ANC) at lakes, and include EPA thresholds #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' ChemLakeANCPlot(conn) -#' ChemLakeANCPlot(conn, site = "GRBA_L_DEAD0") -#' CloseDatabaseConnection(conn) +#' ChemLakeANCPlot() +#' ChemLakeANCPlot(site = "GRBA_L_DEAD0") #' } #' ChemLakeANCPlot <- function(park, site, field.season) { chem.anc <- ChemANC(park = park, site = site, field.season = field.season) - chem.lake.anc <- chem.anc %>% + chem.lake.anc <- chem.anc |> dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) @@ -497,28 +446,23 @@ ChemLakeANCPlot <- function(park, site, field.season) { #' Plot acid neutralizing capacity (ANC) at streams, and include EPA thresholds #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' ChemStreamANCPlot(conn) -#' ChemStreamANCPlot(conn, site = "GRBA_S_PINE1") -#' CloseDatabaseConnection(conn) +#' ChemStreamANCPlot() +#' ChemStreamANCPlot(site = "GRBA_S_PINE1") #' } ChemStreamANCPlot <- function(park, site, field.season) { chem.anc <- ChemANC(park = park, site = site, field.season = field.season) - chem.stream.anc <- chem.anc %>% + chem.stream.anc <- chem.anc |> dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) @@ -554,8 +498,8 @@ ChemLakeNutrientPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - lake.nut <- chem %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") %>% + lake.nut <- chem |> + dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") |> tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) lake.nut$Characteristic_f = factor(lake.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) @@ -592,9 +536,9 @@ ChemLakeNutrientBarPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - lake.nut.bar <- chem %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") %>% - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) %>% + lake.nut.bar <- chem |> + dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) |> dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) @@ -602,8 +546,9 @@ ChemLakeNutrientBarPlot <- function(park, site, field.season) { lake.nut.bar$Nutrient_f = factor(lake.nut.bar$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) lake.nut.bar$Characteristic_f = factor(lake.nut.bar$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) - lake.nut.bar %<>% dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) %>% - filter(Characteristic != "DOC") + lake.nut.bar <- lake.nut.bar |> + dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) |> + dplyr::filter(Characteristic != "DOC") lake.nut.bar.plot <- ggplot2::ggplot(lake.nut.bar, ggplot2::aes(x = FieldSeason, y = LabValue, @@ -636,9 +581,9 @@ ChemLakeIonPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - lake.ion <- chem %>% + lake.ion <- chem |> dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Ion", - Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) %>% + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) |> tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) lake.ion$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) @@ -674,8 +619,8 @@ ChemStreamNutrientPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - stream.nut <- chem %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") %>% + stream.nut <- chem |> + dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") |> tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) stream.nut$Characteristic_f = factor(stream.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) @@ -710,9 +655,9 @@ ChemStreamNutrientPlot <- function(park, site, field.season) { ChemStreamNutrientBarPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - stream.nut.bar <- chem %>% - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") %>% - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) %>% + stream.nut.bar <- chem |> + dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) |> dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) @@ -720,8 +665,9 @@ ChemStreamNutrientBarPlot <- function(park, site, field.season) { stream.nut.bar$Nutrient_f = factor(stream.nut.bar$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) stream.nut.bar$Characteristic_f = factor(stream.nut.bar$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) - stream.nut.bar %<>% dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) %>% - filter(Characteristic != "DOC") + stream.nut.bar <- stream.nut.bar |> + dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) |> + dplyr::filter(Characteristic != "DOC") stream.nut.bar.plot <- ggplot2::ggplot(stream.nut.bar, ggplot2::aes(x = FieldSeason, y = LabValue, @@ -753,9 +699,9 @@ ChemStreamIonPlot <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") - stream.ion <- chem %>% + stream.ion <- chem |> dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Ion", SiteShort != "BAKR2", - Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) %>% + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) |> tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) stream.ion$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) diff --git a/R/clarity-qc.R b/R/clarity-qc.R index cc6c613..f4f4ee1 100644 --- a/R/clarity-qc.R +++ b/R/clarity-qc.R @@ -1,24 +1,16 @@ #' List secchi depth measurements that are greater than the recorded lake depth #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcSecchiGTDepth(conn) -#' qcSecchiGTDepth(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' qcSecchiGTDepth(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcSecchiGTDepth() +#' qcSecchiGTDepth(site = "GRBA_L_BAKR0", field.season = "2019") #' } qcSecchiGTDepth <- function(park, site, field.season) { @@ -32,25 +24,17 @@ qcSecchiGTDepth <- function(park, site, field.season) { #' List clarity records where lake is dry but clarity measurements exist #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. +#' @return A tibble #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcLakeDryMeasurementsExist(conn) -#' qcLakeDryMeasurementsExist(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' qcLakeDryMeasurementsExist(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcLakeDryMeasurementsExist() +#' qcLakeDryMeasurementsExist(site = "GRBA_L_BAKR0", field.season = "2019") #' } qcLakeDryMeasurementsExist <- function(park, site, field.season) { @@ -65,25 +49,17 @@ qcLakeDryMeasurementsExist <- function(park, site, field.season) { #' List clarity records where lake is not dry but measurements are missing #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcLakeNotDryMeasurementsMissing(conn) -#' qcLakeNotDryMeasurementsMissing(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' qcLakeNotDryMeasurementsMissing(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcLakeNotDryMeasurementsMissing() +#' qcLakeNotDryMeasurementsMissing(site = "GRBA_L_BAKR0", field.season = "2019") #' } qcLakeNotDryMeasurementsMissing <- function(park, site, field.season) { @@ -98,25 +74,17 @@ qcLakeNotDryMeasurementsMissing <- function(park, site, field.season) { #' List clarity records where secchi disk is not on bottom but secchi depth measurement is missing #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_DEAD0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. +#' @return A tibble #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcDepthMissing(conn) -#' qcDepthMissing(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' qcDepthMissing(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcDepthMissing() +#' qcDepthMissing(site = "GRBA_L_BAKR0", field.season = "2019") #' } qcSecchiDepthMissing <- function(park, site, field.season) { diff --git a/R/efficiency-qc.R b/R/efficiency-qc.R index d68c333..e9dedb6 100644 --- a/R/efficiency-qc.R +++ b/R/efficiency-qc.R @@ -7,22 +7,20 @@ #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcNoAnnualVisit(conn) -#' qcNoAnnualVisit(conn, site = "GRBA_L_DEAD0", field.season = c("2012", "2013", "2014", "2015")) -#' CloseDatabaseConnection(conn) +#' qcNoAnnualVisit() +#' qcNoAnnualVisit(site = "GRBA_L_DEAD0", field.season = c("2012", "2013", "2014", "2015")) #' } qcNoAnnualVisit <- function(park, site, field.season) { visit.data <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") -visit <- visit.data %>% - dplyr::select(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame, VisitDate, FieldSeason, VisitType, MonitoringStatus) %>% - dplyr::filter(VisitType == "Primary", SiteCode != "GRBA_S_BAKR2") %>% +visit <- visit.data |> + dplyr::select(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame, VisitDate, FieldSeason, VisitType, MonitoringStatus) |> + dplyr::filter(VisitType == "Primary", SiteCode != "GRBA_S_BAKR2") |> tidyr::pivot_wider(id_cols = c(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame), names_from = FieldSeason, - values_from = VisitDate) %>% - tidyr::pivot_longer(!c(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame), names_to = "FieldSeason", values_to = "VisitDate") %>% - dplyr::filter(is.na(VisitDate)) %>% + values_from = VisitDate) |> + tidyr::pivot_longer(!c(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame), names_to = "FieldSeason", values_to = "VisitDate") |> + dplyr::filter(is.na(VisitDate)) |> dplyr::select(Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, VisitDate) return(visit) @@ -34,15 +32,13 @@ return(visit) #' #' @inheritParams ReadAndFilterData #' -#' @return A tibble with columns SiteCode, SiteName, VisitDate, FieldSeason, SampleFrame, VisitType, Visit.DPL, Chem.DPL, BMI.DPL, Channel.DPL, Clarity.DPL, LakeSurvey.DPL, LakeString.DPL, Xsection.DPL, TempC.DPL, pH.DPL, SpCond.DPL, DO.DPL +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcDPLCheck(conn) -#' qcDPLCheck(conn, site = "GRBA_L_JHNS0", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcDPLCheck() +#' qcDPLCheck(site = "GRBA_L_JHNS0", field.season = c("2018", "2019", "2020")) #' } qcDPLCheck <- function(park, site, field.season) { @@ -59,69 +55,69 @@ qcDPLCheck <- function(park, site, field.season) { spcond <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualitySpCond") do <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "WaterQualityDO") - visit.DPL <- visit %>% - dplyr::rename(Visit.DPL = DataProcessingLevel) %>% + visit.DPL <- visit |> + dplyr::rename(Visit.DPL = DataProcessingLevel) |> dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, SampleFrame, VisitType, Visit.DPL) - chem.DPL <- chem %>% - dplyr::filter(SampleType == "Routine") %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SampleFrame, DPL) %>% - dplyr::rename(Chem.DPL = DPL) %>% + chem.DPL <- chem |> + dplyr::filter(SampleType == "Routine") |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SampleFrame, DPL) |> + dplyr::rename(Chem.DPL = DPL) |> dplyr::distinct() - # bmi.DPL <- bmi %>% - # dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - # dplyr::rename(BMI.DPL = DPL) %>% + # bmi.DPL <- bmi |> + # dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + # dplyr::rename(BMI.DPL = DPL) |> # dplyr::distinct() - channel.DPL <- channel %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, DPL) %>% - dplyr::rename(Channel.DPL = DPL) %>% + channel.DPL <- channel |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, DPL) |> + dplyr::rename(Channel.DPL = DPL) |> dplyr::distinct() - clarity.DPL <- clarity %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(Clarity.DPL = DPL) %>% + clarity.DPL <- clarity |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(Clarity.DPL = DPL) |> dplyr::distinct() - lakesurvey.DPL <- lakesurvey %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(LakeSurvey.DPL = DPL) %>% + lakesurvey.DPL <- lakesurvey |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(LakeSurvey.DPL = DPL) |> dplyr::distinct() - lakestring.DPL <- lakestring %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(LakeString.DPL = DPL) %>% + lakestring.DPL <- lakestring |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(LakeString.DPL = DPL) |> dplyr::distinct() - xsection.DPL <- xsection %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(Xsection.DPL = DPL) %>% + xsection.DPL <- xsection |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(Xsection.DPL = DPL) |> dplyr::distinct() - temp.DPL <- temp %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(TempC.DPL = DPL) %>% + temp.DPL <- temp |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(TempC.DPL = DPL) |> dplyr::distinct() - ph.DPL <- ph %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(pH.DPL = DPL) %>% + ph.DPL <- ph |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(pH.DPL = DPL) |> dplyr::distinct() - spcond.DPL <- spcond %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(SpCond.DPL = DPL) %>% + spcond.DPL <- spcond |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(SpCond.DPL = DPL) |> dplyr::distinct() - do.DPL <- do %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>% - dplyr::rename(DO.DPL = DPL) %>% + do.DPL <- do |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) |> + dplyr::rename(DO.DPL = DPL) |> dplyr::distinct() - dpl <- visit.DPL %>% - dplyr::left_join(chem.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SampleFrame", "VisitType")) %>% - # dplyr::left_join(bmi.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(channel.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) %>% - dplyr::left_join(clarity.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(lakesurvey.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(lakestring.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(xsection.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(temp.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(ph.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(spcond.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - dplyr::left_join(do.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) %>% - unique() %>% - dplyr::filter_all(any_vars(. %in% c("Raw", "Provisional"))) %>% + dpl <- visit.DPL |> + dplyr::left_join(chem.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SampleFrame", "VisitType")) |> + # dplyr::left_join(bmi.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(channel.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) |> + dplyr::left_join(clarity.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(lakesurvey.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(lakestring.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(xsection.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(temp.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(ph.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(spcond.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + dplyr::left_join(do.DPL, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "VisitType")) |> + unique() |> + dplyr::filter_all(any_vars(. %in% c("Raw", "Provisional"))) |> dplyr::arrange(SampleFrame, FieldSeason, SiteCode) return(dpl) @@ -133,15 +129,13 @@ return(dpl) #' #' @inheritParams ReadAndFilterData #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Date, Parameter, Units, Value, Grade. +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' WqDailyMeanLong(conn) -#' WqDailyMeanLong(conn, site = "GRBA_S_LHMN1", field.season = c("2012", "2013", "2014", "2015")) -#' CloseDatabaseConnection(conn) +#' WqDailyMeanLong() +#' WqDailyMeanLong(site = "GRBA_S_LHMN1", field.season = c("2012", "2013", "2014", "2015")) #' } WqDailyMeanLong <- function(park, site, field.season) { @@ -152,115 +146,115 @@ WqDailyMeanLong <- function(park, site, field.season) { do.mgl <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "TimeseriesDOmgl") visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") - wt.long <- wt %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% - dplyr::rename(WaterTemperature_C = Value) %>% + wt.long <- wt |> + dplyr::filter(Approval == "Approved") |> + dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) |> + dplyr::rename(WaterTemperature_C = Value) |> dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, - Date) %>% + Date) |> dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(WaterTemperature_C)) > 77 ~ mean(WaterTemperature_C, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(WaterTemperature_C)) > 19 ~ mean(WaterTemperature_C, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = dplyr::case_when(!is.na(WaterTemperature_C) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% - unique() %>% - dplyr::mutate(Parameter = "Temperature") %>% - dplyr::mutate(Units = "C") %>% - dplyr::arrange(Park, SiteCode, Date) %>% - dplyr::filter(!is.na(Value)) %>% - dplyr::relocate(Parameter, .after = Date) %>% - dplyr::relocate(Units, .after = Parameter) %>% + Grade = dplyr::case_when(!is.na(WaterTemperature_C) ~ statip::mfv1(Grade, na_rm = TRUE))) |> + unique() |> + dplyr::mutate(Parameter = "Temperature") |> + dplyr::mutate(Units = "C") |> + dplyr::arrange(Park, SiteCode, Date) |> + dplyr::filter(!is.na(Value)) |> + dplyr::relocate(Parameter, .after = Date) |> + dplyr::relocate(Units, .after = Parameter) |> dplyr::ungroup() - ph.long <- ph %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% - dplyr::rename(pH = Value) %>% + ph.long <- ph |> + dplyr::filter(Approval == "Approved") |> + dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) |> + dplyr::rename(pH = Value) |> dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, - Date) %>% + Date) |> dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(pH)) > 77 ~ median(pH, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(pH)) > 19 ~ median(pH, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = dplyr::case_when(!is.na(pH) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% - unique() %>% - dplyr::mutate(Parameter = "pH") %>% - dplyr::mutate(Units = "units") %>% - dplyr::arrange(Park, SiteCode, Date) %>% - dplyr::filter(!is.na(Value)) %>% - dplyr::relocate(Parameter, .after = Date) %>% - dplyr::relocate(Units, .after = Parameter) %>% + Grade = dplyr::case_when(!is.na(pH) ~ statip::mfv1(Grade, na_rm = TRUE))) |> + unique() |> + dplyr::mutate(Parameter = "pH") |> + dplyr::mutate(Units = "units") |> + dplyr::arrange(Park, SiteCode, Date) |> + dplyr::filter(!is.na(Value)) |> + dplyr::relocate(Parameter, .after = Date) |> + dplyr::relocate(Units, .after = Parameter) |> dplyr::ungroup() - sc.long <- sc %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% - dplyr::rename(SpecificConductance_microS_per_cm = Value) %>% + sc.long <- sc |> + dplyr::filter(Approval == "Approved") |> + dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) |> + dplyr::rename(SpecificConductance_microS_per_cm = Value) |> dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, - Date) %>% + Date) |> dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(SpecificConductance_microS_per_cm)) > 77 ~ mean(SpecificConductance_microS_per_cm, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(SpecificConductance_microS_per_cm)) > 19 ~ mean(SpecificConductance_microS_per_cm, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = dplyr::case_when(!is.na(SpecificConductance_microS_per_cm) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% - unique() %>% - dplyr::mutate(Parameter = "SpCond") %>% - dplyr::mutate(Units = "uS/cm") %>% - dplyr::arrange(Park, SiteCode, Date) %>% - dplyr::filter(!is.na(Value)) %>% - dplyr::relocate(Parameter, .after = Date) %>% - dplyr::relocate(Units, .after = Parameter) %>% + Grade = dplyr::case_when(!is.na(SpecificConductance_microS_per_cm) ~ statip::mfv1(Grade, na_rm = TRUE))) |> + unique() |> + dplyr::mutate(Parameter = "SpCond") |> + dplyr::mutate(Units = "uS/cm") |> + dplyr::arrange(Park, SiteCode, Date) |> + dplyr::filter(!is.na(Value)) |> + dplyr::relocate(Parameter, .after = Date) |> + dplyr::relocate(Units, .after = Parameter) |> dplyr::ungroup() - do.pct.long <- do.pct %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% - dplyr::rename(DissolvedOxygen_percent = Value) %>% + do.pct.long <- do.pct |> + dplyr::filter(Approval == "Approved") |> + dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) |> + dplyr::rename(DissolvedOxygen_percent = Value) |> dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, - Date) %>% + Date) |> dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_percent)) > 77 ~ mean(DissolvedOxygen_percent, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(DissolvedOxygen_percent)) > 19 ~ mean(DissolvedOxygen_percent, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = dplyr::case_when(!is.na(DissolvedOxygen_percent) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% - unique() %>% - dplyr::mutate(Parameter = "DO") %>% - dplyr::mutate(Units = "%") %>% - dplyr::arrange(Park, SiteCode, Date) %>% - dplyr::filter(!is.na(Value)) %>% - dplyr::relocate(Parameter, .after = Date) %>% - dplyr::relocate(Units, .after = Parameter) %>% + Grade = dplyr::case_when(!is.na(DissolvedOxygen_percent) ~ statip::mfv1(Grade, na_rm = TRUE))) |> + unique() |> + dplyr::mutate(Parameter = "DO") |> + dplyr::mutate(Units = "%") |> + dplyr::arrange(Park, SiteCode, Date) |> + dplyr::filter(!is.na(Value)) |> + dplyr::relocate(Parameter, .after = Date) |> + dplyr::relocate(Units, .after = Parameter) |> dplyr::ungroup() - do.mgl.long <- do.mgl %>% - dplyr::filter(Approval == "Approved") %>% - dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>% - dplyr::rename(DissolvedOxygen_mgL = Value) %>% + do.mgl.long <- do.mgl |> + dplyr::filter(Approval == "Approved") |> + dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) |> + dplyr::rename(DissolvedOxygen_mgL = Value) |> dplyr::group_by(Park, SiteCode, SampleFrame, FieldSeason, - Date) %>% + Date) |> dplyr::summarise(Value = dplyr::case_when(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012 & sum(!is.na(DissolvedOxygen_mgL)) > 77 ~ mean(DissolvedOxygen_mgL, na.rm = TRUE), !(SiteCode == "GRBA_S_SNKE1" & FieldSeason == 2012) & sum(!is.na(DissolvedOxygen_mgL)) > 19 ~ mean(DissolvedOxygen_mgL, na.rm = TRUE), TRUE ~ as.double(NA_integer_)), - Grade = dplyr::case_when(!is.na(DissolvedOxygen_mgL) ~ statip::mfv1(Grade, na_rm = TRUE))) %>% - unique() %>% - dplyr::mutate(Parameter = "DO") %>% - dplyr::mutate(Units = "mg/L") %>% - dplyr::arrange(Park, SiteCode, Date) %>% - dplyr::filter(!is.na(Value)) %>% - dplyr::relocate(Parameter, .after = Date) %>% - dplyr::relocate(Units, .after = Parameter) %>% - dplyr::mutate(Grade = as.character(Grade)) %>% + Grade = dplyr::case_when(!is.na(DissolvedOxygen_mgL) ~ statip::mfv1(Grade, na_rm = TRUE))) |> + unique() |> + dplyr::mutate(Parameter = "DO") |> + dplyr::mutate(Units = "mg/L") |> + dplyr::arrange(Park, SiteCode, Date) |> + dplyr::filter(!is.na(Value)) |> + dplyr::relocate(Parameter, .after = Date) |> + dplyr::relocate(Units, .after = Parameter) |> + dplyr::mutate(Grade = as.character(Grade)) |> dplyr::ungroup() wq.long.int <- dplyr::bind_rows(wt.long, ph.long, sc.long, do.pct.long, do.mgl.long) @@ -269,13 +263,13 @@ WqDailyMeanLong <- function(park, site, field.season) { SiteCode = c("GRBA_S_BAKR1", "GRBA_S_LHMN1", "GRBA_S_SNKE1", "GRBA_S_SNKE3", "GRBA_S_STRW1"), SiteName = c("Baker Creek (Gage)", "Lehman Creek (Gage)", "Snake Creek (Lower)", "Snake Creek (Upper)", "Strawberry Creek (Gage)")) - visit.names <- visit %>% - dplyr::select(SiteShort, SiteCode, SiteName) %>% - unique() %>% + visit.names <- visit |> + dplyr::select(SiteShort, SiteCode, SiteName) |> + unique() |> dplyr::bind_rows(gage.locations) - wq.long <- dplyr::left_join(wq.long.int, visit.names, by = c("SiteCode")) %>% - dplyr::relocate(SiteShort, .before = SiteCode) %>% + wq.long <- dplyr::left_join(wq.long.int, visit.names, by = c("SiteCode")) |> + dplyr::relocate(SiteShort, .before = SiteCode) |> dplyr::relocate(SiteName, .after = SiteCode) return(wq.long) @@ -285,31 +279,26 @@ WqDailyMeanLong <- function(park, site, field.season) { #' Return summary of daily mean values (daily median values for pH) and grades for water quality parameters at streams. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, SiteType, Date, FieldSeason, Temp_C, Temp_C_Grade, pH, pH_Grade, SpCond_uScm, SpCond_uScm_Grade, DO_pct, DO_pct_Grade, DO_mgL, DO_mgL_Grade +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' WqDailyMean(conn) -#' WqDailyMean(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' WqDailyMean() +#' WqDailyMean(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } WqDailyMean <- function(park, site, field.season) { wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) -wq.daily <- wq.long %>% - tidyr::unite(Parameter, c("Parameter", "Units")) %>% +wq.daily <- wq.long |> + tidyr::unite(Parameter, c("Parameter", "Units")) |> tidyr::pivot_wider(names_from = Parameter, - values_from = c(Value, Grade)) %>% + values_from = c(Value, Grade)) |> plyr::rename(replace = c(Value_Temperature_C = "Temp_C", Value_pH_units = "pH", `Value_SpCond_uS/cm` = "SpCond_uScm", @@ -320,7 +309,7 @@ wq.daily <- wq.long %>% `Grade_SpCond_uS/cm` = "SpCond_uScm_Grade", `Grade_DO_%` = "DO_pct_Grade", `Grade_DO_mg/L` = "DO_mgL_Grade"), - warn_missing = FALSE) %>% + warn_missing = FALSE) |> dplyr::select(Park, SiteShort, SiteCode, SiteName, SampleFrame, Date, FieldSeason, Temp_C, Temp_C_Grade, pH, pH_Grade, SpCond_uScm, SpCond_uScm_Grade, DO_pct, DO_pct_Grade, everything()) return(wq.daily) @@ -330,31 +319,26 @@ return(wq.daily) #' Calculate the number and percentage of days of data for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days). #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcWqCompleteness(conn) -#' qcWqCompleteness(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcWqCompleteness() +#' qcWqCompleteness(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } qcWqCompleteness <- function(park, site, field.season) { wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) -wq.comp <- wq.long %>% +wq.comp <- wq.long |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::group_by(Park, SiteShort, SiteCode, @@ -362,12 +346,12 @@ wq.comp <- wq.long %>% SampleFrame, FieldSeason, Parameter, - Units) %>% - dplyr::summarise(CompletedDays = sum(!is.na(Value))) %>% - dplyr::mutate(PercentCompleteness = CompletedDays/77*100) %>% - dplyr::ungroup() %>% - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(CompletedDays = 0, PercentCompleteness = 0)) %>% - dplyr::relocate(FieldSeason, .after = SampleFrame) %>% + Units) |> + dplyr::summarise(CompletedDays = sum(!is.na(Value))) |> + dplyr::mutate(PercentCompleteness = CompletedDays/77*100) |> + dplyr::ungroup() |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(CompletedDays = 0, PercentCompleteness = 0)) |> + dplyr::relocate(FieldSeason, .after = SampleFrame) |> dplyr::arrange(SiteCode, FieldSeason, Parameter) wq.comp$PercentCompleteness <- round(wq.comp$PercentCompleteness, 2) @@ -379,38 +363,33 @@ return(wq.comp) #' Calculate percentage of data rated at each grade level for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days). Long format for ease of plotting. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcWqGradesLong(conn) -#' qcWqGradesLong(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcWqGradesLong() +#' qcWqGradesLong(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } qcWqGradesLong <- function(park, site, field.season) { wq.long <- WqDailyMeanLong(park = park, site = site, field.season = field.season) -wq.grds.long <- wq.long %>% +wq.grds.long <- wq.long |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% - dplyr::select(-c(Month, Day)) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Parameter, Units, Grade) %>% - dplyr::summarise(Days = dplyr::n()) %>% - dplyr::mutate(Percent = Days/sum(Days)*100) %>% - dplyr::ungroup() %>% - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(Days = 0, Percent = 0)) %>% - dplyr::relocate(FieldSeason, .after = SampleFrame) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> + dplyr::select(-c(Month, Day)) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Parameter, Units, Grade) |> + dplyr::summarise(Days = dplyr::n()) |> + dplyr::mutate(Percent = Days/sum(Days)*100) |> + dplyr::ungroup() |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(Days = 0, Percent = 0)) |> + dplyr::relocate(FieldSeason, .after = SampleFrame) |> dplyr::arrange(SiteCode, FieldSeason, Parameter, Grade) @@ -421,147 +400,142 @@ return(wq.grds.long) #' Calculate the percentage of data rated at each grade level for each water quality parameter for each field season between the index period of July 1 to September 15 (77 days). #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcWqGrades(conn) -#' qcWqGrades(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcWqGrades() +#' qcWqGrades(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } qcWqGrades <- function(park, site, field.season) { wq.daily <- WqDailyMean(park = park, site = site, field.season = field.season) -wt.grds <- wq.daily %>% +wt.grds <- wq.daily |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, - FieldSeason) %>% + FieldSeason) |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::summarise(DaysExcellent = sum(Temp_C_Grade %in% c("Excellent", "Est. Excellent")), DaysGood = sum(Temp_C_Grade %in% c("Good", "Est. Good")), DaysFair = sum(Temp_C_Grade %in% c("Fair", "Est. Fair")), - DaysPoor = sum(Temp_C_Grade %in% c("Poor", "Est. Poor"))) %>% - dplyr::rowwise() %>% - dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) %>% + DaysPoor = sum(Temp_C_Grade %in% c("Poor", "Est. Poor"))) |> + dplyr::rowwise() |> + dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) |> dplyr::mutate(PercentExcellent = DaysExcellent/TotalDays*100, PercentGood = DaysGood/TotalDays*100, PercentFair = DaysFair/TotalDays*100, - PercentPoor = DaysPoor/TotalDays*100) %>% - dplyr::mutate(Parameter = "Temperature") %>% - dplyr::mutate(Units = "C") %>% + PercentPoor = DaysPoor/TotalDays*100) |> + dplyr::mutate(Parameter = "Temperature") |> + dplyr::mutate(Units = "C") |> dplyr::ungroup() -ph.grds <- wq.daily %>% +ph.grds <- wq.daily |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, - FieldSeason) %>% + FieldSeason) |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::summarise(DaysExcellent = sum(pH_Grade %in% c("Excellent", "Est. Excellent")), DaysGood = sum(pH_Grade %in% c("Good", "Est. Good")), DaysFair = sum(pH_Grade %in% c("Fair", "Est. Fair")), - DaysPoor = sum(pH_Grade %in% c("Poor", "Est. Poor"))) %>% - dplyr::rowwise() %>% - dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) %>% + DaysPoor = sum(pH_Grade %in% c("Poor", "Est. Poor"))) |> + dplyr::rowwise() |> + dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) |> dplyr::mutate(PercentExcellent = DaysExcellent/TotalDays*100, PercentGood = DaysGood/TotalDays*100, PercentFair = DaysFair/TotalDays*100, - PercentPoor = DaysPoor/TotalDays*100) %>% - dplyr::mutate(Parameter = "pH") %>% - dplyr::mutate(Units = "units") %>% + PercentPoor = DaysPoor/TotalDays*100) |> + dplyr::mutate(Parameter = "pH") |> + dplyr::mutate(Units = "units") |> dplyr::ungroup() -sc.grds <- wq.daily %>% +sc.grds <- wq.daily |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, - FieldSeason) %>% + FieldSeason) |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::summarise(DaysExcellent = sum(SpCond_uScm_Grade %in% c("Excellent", "Est. Excellent")), DaysGood = sum(SpCond_uScm_Grade %in% c("Good", "Est. Good")), DaysFair = sum(SpCond_uScm_Grade %in% c("Fair", "Est. Fair")), - DaysPoor = sum(SpCond_uScm_Grade %in% c("Poor", "Est. Poor"))) %>% - dplyr::rowwise() %>% - dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) %>% + DaysPoor = sum(SpCond_uScm_Grade %in% c("Poor", "Est. Poor"))) |> + dplyr::rowwise() |> + dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) |> dplyr::mutate(PercentExcellent = DaysExcellent/TotalDays*100, PercentGood = DaysGood/TotalDays*100, PercentFair = DaysFair/TotalDays*100, - PercentPoor = DaysPoor/TotalDays*100) %>% - dplyr::mutate(Parameter = "SpCond") %>% - dplyr::mutate(Units = "uS/cm") %>% + PercentPoor = DaysPoor/TotalDays*100) |> + dplyr::mutate(Parameter = "SpCond") |> + dplyr::mutate(Units = "uS/cm") |> dplyr::ungroup() -do.pct.grds <- wq.daily %>% +do.pct.grds <- wq.daily |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, - FieldSeason) %>% + FieldSeason) |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::summarise(DaysExcellent = sum(DO_pct_Grade %in% c("Excellent", "Est. Excellent")), DaysGood = sum(DO_pct_Grade %in% c("Good", "Est. Good")), DaysFair = sum(DO_pct_Grade %in% c("Fair", "Est. Fair")), - DaysPoor = sum(DO_pct_Grade %in% c("Poor", "Est. Poor"))) %>% - dplyr::rowwise() %>% - dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) %>% + DaysPoor = sum(DO_pct_Grade %in% c("Poor", "Est. Poor"))) |> + dplyr::rowwise() |> + dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) |> dplyr::mutate(PercentExcellent = DaysExcellent/TotalDays*100, PercentGood = DaysGood/TotalDays*100, PercentFair = DaysFair/TotalDays*100, - PercentPoor = DaysPoor/TotalDays*100) %>% - dplyr::mutate(Parameter = "DO") %>% - dplyr::mutate(Units = "%") %>% + PercentPoor = DaysPoor/TotalDays*100) |> + dplyr::mutate(Parameter = "DO") |> + dplyr::mutate(Units = "%") |> dplyr::ungroup() if ("DO_mgL" %in% colnames(wq.daily)) { -do.mgl.grds <- wq.daily %>% +do.mgl.grds <- wq.daily |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, - FieldSeason) %>% + FieldSeason) |> dplyr::mutate(Month = lubridate::month(Date), - Day = lubridate::day(Date)) %>% - dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) %>% + Day = lubridate::day(Date)) |> + dplyr::filter(Month == 7 | Month == 8 | (Month == 9 & Day <= 15)) |> dplyr::summarise(DaysExcellent = sum(DO_mgL_Grade %in% c("Excellent", "Est. Excellent")), DaysGood = sum(DO_mgL_Grade %in% c("Good", "Est. Good")), DaysFair = sum(DO_mgL_Grade %in% c("Fair", "Est. Fair")), - DaysPoor = sum(DO_mgL_Grade %in% c("Poor", "Est. Poor"))) %>% - dplyr::rowwise() %>% - dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) %>% + DaysPoor = sum(DO_mgL_Grade %in% c("Poor", "Est. Poor"))) |> + dplyr::rowwise() |> + dplyr::mutate(TotalDays = sum(c_across(where(is.integer)))) |> dplyr::mutate(PercentExcellent = DaysExcellent/TotalDays*100, PercentGood = DaysGood/TotalDays*100, PercentFair = DaysFair/TotalDays*100, - PercentPoor = DaysPoor/TotalDays*100) %>% - dplyr::mutate(Parameter = "DO") %>% - dplyr::mutate(Units = "mg/L") %>% + PercentPoor = DaysPoor/TotalDays*100) |> + dplyr::mutate(Parameter = "DO") |> + dplyr::mutate(Units = "mg/L") |> dplyr::ungroup() } else { @@ -585,7 +559,7 @@ do.mgl.grds <- tibble::tibble(Park = character(), } -wq.grds <- dplyr::bind_rows(wt.grds, ph.grds, sc.grds, do.pct.grds, do.mgl.grds) %>% +wq.grds <- dplyr::bind_rows(wt.grds, ph.grds, sc.grds, do.pct.grds, do.mgl.grds) |> dplyr::select(Park, SiteShort, SiteCode, @@ -601,7 +575,7 @@ wq.grds <- dplyr::bind_rows(wt.grds, ph.grds, sc.grds, do.pct.grds, do.mgl.grds) DaysFair, PercentFair, DaysPoor, - PercentPoor) %>% + PercentPoor) |> tidyr::complete(FieldSeason, nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Parameter, Units), fill = list(DaysExcellent = 0, PercentExcellent = 0, DaysGood = 0, @@ -609,8 +583,8 @@ wq.grds <- dplyr::bind_rows(wt.grds, ph.grds, sc.grds, do.pct.grds, do.mgl.grds) DaysFair = 0, PercentFair = 0, DaysPoor = 0, - PercentPoor = 0)) %>% - dplyr::relocate(FieldSeason, .after = SampleFrame) %>% + PercentPoor = 0)) |> + dplyr::relocate(FieldSeason, .after = SampleFrame) |> dplyr::arrange(SiteCode, FieldSeason, Parameter) wq.grds$PercentExcellent <- round(wq.grds$PercentExcellent, 2) @@ -625,28 +599,23 @@ return(wq.grds) #' Plot percent completeness for each water quality parameter for each stream for each field season. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcWqCompletenessPlot(conn) -#' qcWqCompletenessPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcWqCompletenessPlot() +#' qcWqCompletenessPlot(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } qcWqCompletenessPlot <- function(park, site, field.season) { wq.comp <- qcWqCompleteness(park = park, site = site, field.season = field.season) -wq.comp.concat <- wq.comp %>% +wq.comp.concat <- wq.comp |> tidyr::unite("Parameter", Parameter, Units, sep = "_") wq.comp.concat$Parameter_f = factor(wq.comp.concat$Parameter, levels = c("Temperature_C", "pH_units", "SpCond_uS/cm", "DO_%", "DO_mg/L")) @@ -664,28 +633,23 @@ return(wq.comp.plot) #' Plot the percentage of data rated at each grade level for each water quality parameter for each field season. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' #' @return A ggplot object #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcWqGradesPlot(conn) -#' qcWqGradesPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) -#' CloseDatabaseConnection(conn) +#' qcWqGradesPlot() +#' qcWqGradesPlot(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) #' } qcWqGradesPlot <- function(park, site, field.season) { wq.grds.long <- qcWqGradesLong(park = park, site = site, field.season = field.season) -wq.grds.concat <- wq.grds.long %>% +wq.grds.concat <- wq.grds.long |> tidyr::unite("Parameter", Parameter, Units, sep = "_") wq.grds.concat$Parameter_f = factor(wq.grds.concat$Parameter, levels = c("Temperature_C", "pH_units", "SpCond_uS/cm", "DO_%", "DO_mg/L")) diff --git a/R/levels-qc.R b/R/levels-qc.R index c20f682..07b5247 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -2,31 +2,27 @@ #' #' @inheritParams ReadAndFilterData #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason,VisitType, DPL, SurveyPoint, Benchmark, FinalCorrectedElevation_ft. +#' @return A tibble #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' SurveyPointElevation(conn) -#' SurveyPointElevation(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' SurveyPointElevation(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' SurveyPointElevation() +#' SurveyPointElevation(site = "GRBA_L_BAKR0", field.season = "2019") #' } SurveyPointElevation <- function(park, site, field.season) { levels.import <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") dry <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") # Data to filter out dry lakes StandardTemperature_F <- 68 # Standard temperature to be used for temperature corrections - dry %<>% dplyr::select(SiteCode, VisitDate, FieldSeason, IsLakeDry) + dry <- dry |> + dplyr::select(SiteCode, VisitDate, FieldSeason, IsLakeDry) # Parse out survey point names, types, and setup number. Consolidate rod temperature into one column - levels <- levels.import %>% - dplyr::inner_join(dry, by = c("SiteCode", "VisitDate", "FieldSeason")) %>% - dplyr::filter(IsLakeDry != TRUE) %>% - tidyr::separate(SurveyPointType, into = c("SurveyPoint", "ReadingType", "SetupNumber"), sep = "-", remove = TRUE) %>% + levels <- levels.import |> + dplyr::inner_join(dry, by = c("SiteCode", "VisitDate", "FieldSeason")) |> + dplyr::filter(IsLakeDry != TRUE) |> + tidyr::separate(SurveyPointType, into = c("SurveyPoint", "ReadingType", "SetupNumber"), sep = "-", remove = TRUE) |> dplyr::mutate(SetupNumber = readr::parse_number(SetupNumber), RodTemperature_F = ifelse(SetupNumber == 1, RodTemperatureSetup1_F, ifelse(SetupNumber == 2, RodTemperatureSetup2_F, @@ -37,68 +33,71 @@ SurveyPointElevation <- function(park, site, field.season) { ifelse(SurveyPoint == "RM4", RM4, ifelse(SurveyPoint == "RM5", RM5, ifelse(SurveyPoint == "RM6", RM6, - ifelse(SurveyPoint == "WS", "Water Surface", NA)))))))) %>% + ifelse(SurveyPoint == "WS", "Water Surface", NA)))))))) |> dplyr::mutate(TempCorrectedHeight_ft = Height_ft + (CTE * Height_ft * (RodTemperature_F - StandardTemperature_F))) - setups <- unique(levels$SetupNumber) %>% sort() + setups <- unique(levels$SetupNumber) |> sort() temp_corrected_lvls <- tibble::tibble() # Get known elevations and calculate instrument height. Does this need to be a loop? Probably not for (setup in setups) { #TODO: Need to verify that there is only one backsight per survey per setup. We are assuming that RM1_GivenElevation_m applies to the BS of the first setup - bs <- dplyr::filter(levels, ReadingType == "BS", SetupNumber == setup) %>% + bs <- dplyr::filter(levels, ReadingType == "BS", SetupNumber == setup) |> dplyr::select(SiteCode, VisitDate, FieldSeason, VisitType, SetupNumber, SurveyPoint, TempCorrectedHeight_ft, RM1_GivenElevation_m) # Get known elevation used to calculate instrument height if (setup == 1) { - bs %<>% dplyr::mutate(InstrumentHeight_ft = TempCorrectedHeight_ft + measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) + bs <- bs |> + dplyr::mutate(InstrumentHeight_ft = TempCorrectedHeight_ft + measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) } else { # Get prev. setup elevations for whatever we're taking the backsight to - known_elev <- dplyr::filter(temp_corrected_lvls, SetupNumber == setup - 1) %>% + known_elev <- dplyr::filter(temp_corrected_lvls, SetupNumber == setup - 1) |> dplyr::select(SiteCode, VisitDate, FieldSeason, VisitType, SurveyPoint, TempCorrectedElevation_ft) # Join prev. setup elevations to get known elevation, calc. instrument height - bs %<>% dplyr::left_join(known_elev, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SurveyPoint")) %>% - dplyr::mutate(InstrumentHeight_ft = TempCorrectedHeight_ft + TempCorrectedElevation_ft) %>% + bs <- bs |> + dplyr::left_join(known_elev, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SurveyPoint")) |> + dplyr::mutate(InstrumentHeight_ft = TempCorrectedHeight_ft + TempCorrectedElevation_ft) |> dplyr::select(-TempCorrectedElevation_ft) } # Calc elevations for current setup - bs %<>% dplyr::select(-RM1_GivenElevation_m, -TempCorrectedHeight_ft, -SurveyPoint) - temp_lvls <- levels %>% dplyr::filter(SetupNumber == setup) %>% - dplyr::left_join(bs, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SetupNumber")) %>% + bs <- bs |> + dplyr::select(-RM1_GivenElevation_m, -TempCorrectedHeight_ft, -SurveyPoint) + temp_lvls <- levels |> dplyr::filter(SetupNumber == setup) |> + dplyr::left_join(bs, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SetupNumber")) |> dplyr::mutate(TempCorrectedElevation_ft = InstrumentHeight_ft - TempCorrectedHeight_ft) temp_corrected_lvls <- rbind(temp_corrected_lvls, temp_lvls) } # Get given origin elevation - given_origin_elev <- dplyr::filter(temp_corrected_lvls, SetupNumber == 1, ReadingType == "BS") %>% - dplyr::select(SiteCode, VisitDate, FieldSeason, VisitType, SurveyPoint, TempCorrectedElevation_ft) %>% + given_origin_elev <- dplyr::filter(temp_corrected_lvls, SetupNumber == 1, ReadingType == "BS") |> + dplyr::select(SiteCode, VisitDate, FieldSeason, VisitType, SurveyPoint, TempCorrectedElevation_ft) |> dplyr::rename(GivenOriginElevation_ft = TempCorrectedElevation_ft) # Get final origin elevation - final_origin_elev <- dplyr::select(temp_corrected_lvls, SiteCode, VisitDate, FieldSeason, VisitType, SurveyPoint, SetupNumber, NumberOfInstrumentSetups, TempCorrectedElevation_ft) %>% - dplyr::filter(SetupNumber == NumberOfInstrumentSetups) %>% - dplyr::select(-SetupNumber, NumberOfInstrumentSetups) %>% + final_origin_elev <- dplyr::select(temp_corrected_lvls, SiteCode, VisitDate, FieldSeason, VisitType, SurveyPoint, SetupNumber, NumberOfInstrumentSetups, TempCorrectedElevation_ft) |> + dplyr::filter(SetupNumber == NumberOfInstrumentSetups) |> + dplyr::select(-SetupNumber, NumberOfInstrumentSetups) |> dplyr::rename(FinalOriginElevation_ft = TempCorrectedElevation_ft) # Calculate closure error from given and final origin elevations - closure_error <- dplyr::left_join(given_origin_elev, final_origin_elev, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SurveyPoint")) %>% + closure_error <- dplyr::left_join(given_origin_elev, final_origin_elev, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SurveyPoint")) |> dplyr::mutate(ClosureError_ft = GivenOriginElevation_ft - FinalOriginElevation_ft) # Removed absolute value, since it will affect direction of corrections # Calculate final corrected elevation - final_lvls <- dplyr::arrange(temp_corrected_lvls, FieldSeason, SiteCode, VisitType, SetupNumber) %>% - dplyr::left_join(closure_error, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "NumberOfInstrumentSetups", "SurveyPoint")) %>% - tidyr::fill(ClosureError_ft, .direction = "down") %>% + final_lvls <- dplyr::arrange(temp_corrected_lvls, FieldSeason, SiteCode, VisitType, SetupNumber) |> + dplyr::left_join(closure_error, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "NumberOfInstrumentSetups", "SurveyPoint")) |> + tidyr::fill(ClosureError_ft, .direction = "down") |> dplyr::mutate(FinalCorrectedElevation_ft = ifelse(SetupNumber == 1 & ReadingType == "BS", # Added if-else statement, since closure error correction should not be applied to the backsight toward RM-1 during the first instrument setup, since this is the given origin elevation and is fixed. TempCorrectedElevation_ft, - SetupNumber * (ClosureError_ft / NumberOfInstrumentSetups) + TempCorrectedElevation_ft)) %>% - dplyr::mutate(ClosureError_ft = abs(ClosureError_ft)) %>% # Re-added the absolute value calculation applied to closure error. Keep or remove? - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SurveyPoint) %>% - dplyr::mutate(FinalCorrectedElevation_ft = mean(FinalCorrectedElevation_ft)) %>% - dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL, SurveyPoint, Benchmark, ClosureError_ft, FinalCorrectedElevation_ft) %>% - unique() %>% - dplyr::filter(!grepl("TP", SurveyPoint)) %>% - dplyr::ungroup() %>% + SetupNumber * (ClosureError_ft / NumberOfInstrumentSetups) + TempCorrectedElevation_ft)) |> + dplyr::mutate(ClosureError_ft = abs(ClosureError_ft)) |> # Re-added the absolute value calculation applied to closure error. Keep or remove? + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SurveyPoint) |> + dplyr::mutate(FinalCorrectedElevation_ft = mean(FinalCorrectedElevation_ft)) |> + dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL, SurveyPoint, Benchmark, ClosureError_ft, FinalCorrectedElevation_ft) |> + unique() |> + dplyr::filter(!grepl("TP", SurveyPoint)) |> + dplyr::ungroup() |> dplyr::filter(!(SiteShort == "DEAD0" & FieldSeason == "2021" & SurveyPoint == "WS")) return(final_lvls) @@ -111,15 +110,10 @@ SurveyPointElevation <- function(park, site, field.season) { #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason,VisitType, DPL, SurveyType, BenchmarkUsed, ClosureError_ft, FinalElevation_ft. #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' LakeSurfaceElevation(conn) -#' LakeSurfaceElevation(conn, site = "GRBA_L_BAKR0", field.season = "2019") -#' LakeSurfaceElevation(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' LakeSurfaceElevation() +#' LakeSurfaceElevation(site = "GRBA_L_BAKR0", field.season = "2019") #' } LakeSurfaceElevation <- function(park, site, field.season) { @@ -161,37 +155,37 @@ LakeSurfaceElevation <- function(park, site, field.season) { BenchmarkUsed = logical() ) } else { - survey <- SurveyPointElevation(park = park, site = site, field.season = field.season) %>% - dplyr::filter(Benchmark == "Water Surface") %>% + survey <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + dplyr::filter(Benchmark == "Water Surface") |> dplyr::mutate(SurveyType = "Digital Level", - BenchmarkUsed = NA_character_) %>% - dplyr::rename(FinalElevation_ft = FinalCorrectedElevation_ft) %>% - dplyr::select(-SurveyPoint, -Benchmark, -DPL) %>% - dplyr::relocate(SurveyType, .after = "VisitType") %>% + BenchmarkUsed = NA_character_) |> + dplyr::rename(FinalElevation_ft = FinalCorrectedElevation_ft) |> + dplyr::select(-SurveyPoint, -Benchmark, -DPL) |> + dplyr::relocate(SurveyType, .after = "VisitType") |> dplyr::relocate(FinalElevation_ft, .after = "SurveyType") } - string %<>% - dplyr::mutate(BenchmarkNumber = substring(Benchmark, nchar(Benchmark))) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType) %>% + string <- string |> + dplyr::mutate(BenchmarkNumber = substring(Benchmark, nchar(Benchmark))) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType) |> dplyr::mutate(MinBenchmark = min(BenchmarkNumber), - BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) %>% - dplyr::filter(BenchmarkNumber == MinBenchmark) %>% - dplyr::mutate(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) %>% - dplyr::ungroup() %>% + BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> + dplyr::filter(BenchmarkNumber == MinBenchmark) |> + dplyr::mutate(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) |> + dplyr::ungroup() |> dplyr::mutate(BenchmarkUsed = Benchmark, ClosureError_ft = as.double(NA), - SurveyType = "String") %>% - dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) %>% + SurveyType = "String") |> + dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) |> unique() not_all_na <- function(x) any(!is.na(x)) - lake_elevation <- rbind(string, survey) %>% - dplyr::filter((FieldSeason == "2018" & SurveyType == "Digital Level") | FieldSeason != "2018") %>% - dplyr::select(where(not_all_na)) %>% + lake_elevation <- rbind(string, survey) |> + dplyr::filter((FieldSeason == "2018" & SurveyType == "Digital Level") | FieldSeason != "2018") |> + dplyr::select(where(not_all_na)) |> dplyr::mutate(FinalElevation_m = measurements::conv_unit(FinalElevation_ft, "ft", "m"), - ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) %>% + ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) |> dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") return(lake_elevation) @@ -202,33 +196,29 @@ LakeSurfaceElevation <- function(park, site, field.season) { #' @inheritParams ReadAndFilterData #' @param sd_cutoff Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to `sd_cutoff`. #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, Benchmark, MeanElevation_ft, StDevElevation_ft. +#' @return A tibble #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcBenchmarkElevation(conn) -#' qcBenchmarkElevation(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) -#' qcBenchmarkElevation(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcBenchmarkElevation() +#' qcBenchmarkElevation(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) #' } qcBenchmarkElevation <- function(park, site, field.season, sd_cutoff = NA) { lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) - lvls %<>% - dplyr::select(Park, SiteShort, SiteCode, SiteName, Benchmark, FinalCorrectedElevation_ft) %>% - dplyr::filter(Benchmark != "Water Surface") %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, Benchmark) %>% + lvls <- lvls |> + dplyr::select(Park, SiteShort, SiteCode, SiteName, Benchmark, FinalCorrectedElevation_ft) |> + dplyr::filter(Benchmark != "Water Surface") |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, Benchmark) |> dplyr::summarize(MeanElevation_ft = mean(FinalCorrectedElevation_ft), StDevElevation_ft = sd(FinalCorrectedElevation_ft), - Count = n()) %>% + Count = n()) |> dplyr::ungroup() if (!is.na(sd_cutoff)) { - lvls %<>% dplyr::filter(StDevElevation_ft >= sd_cutoff) + lvls <- lvls |> + dplyr::filter(StDevElevation_ft >= sd_cutoff) } return(lvls) @@ -239,28 +229,23 @@ qcBenchmarkElevation <- function(park, site, field.season, sd_cutoff = NA) { #' #' @inheritParams qcBenchmarkElevation #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanHeight_ft, StDevHeight_ft +#' @return A tibble #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcStringSurveyHeights(conn) -#' qcStringSurveyHeights(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) -#' qcStringSurveyHeights(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcStringSurveyHeights() +#' qcStringSurveyHeights(site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) #' } qcStringSurveyHeights <- function(park, site, field.season, sd_cutoff = NA) { - str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) %>% + str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) |> dplyr::summarise(MeanHeight_ft = mean(Height_ft), - StDevHeight_ft = sd(Height_ft)) %>% + StDevHeight_ft = sd(Height_ft)) |> dplyr::ungroup() if (!is.na(sd_cutoff)) { - str_survey %<>% + str_survey <- str_survey dplyr::filter(StDevHeight_ft >= sd_cutoff) } @@ -275,28 +260,23 @@ qcStringSurveyHeights <- function(park, site, field.season, sd_cutoff = NA) { #' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanFinalElevation_ft, StDevFinalElevation_ft #' @export #' -#' @importFrom magrittr %>% %<>% -#' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcStringSurveyElevations(conn) -#' qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) -#' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcStringSurveyElevations() +#' qQcStringSurveyElevations(site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) #' } qcStringSurveyElevations <- function(park, site, field.season, sd_cutoff = NA) { - str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") %>% - dplyr::mutate(BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) %>% - dplyr::summarise(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) %>% - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType) %>% + str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") |> + dplyr::mutate(BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) |> + dplyr::summarise(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType) |> dplyr::summarise(MeanFinalElevation_ft = mean(FinalElevation_ft), - StDevFinalElevation_ft = sd(FinalElevation_ft)) %>% + StDevFinalElevation_ft = sd(FinalElevation_ft)) |> dplyr::ungroup() if (!is.na(sd_cutoff)) { - str_survey %<>% + str_survey <- str_survey dplyr::filter(StDevFinalElevation_ft >= sd_cutoff) } @@ -306,49 +286,43 @@ qcStringSurveyElevations <- function(park, site, field.season, sd_cutoff = NA) { #' Check the difference between benchmark and water surface elevations calculated in R with those calculated in the Survey123 app #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return Tibble +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcStringSurveyElevations(conn) -#' qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2019", "2021")) -#' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcStringSurveyElevations() +#' qQcStringSurveyElevations(site = "GRBA_L_BAKR0", field.season = c("2019", "2021")) #' } qcElevationDiscrepancies <- function(park, site, field.season) { r_elevs <- SurveyPointElevation(park = park, site = site, field.season = field.season) survey_elevs <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") - r_elevs_data <- r_elevs %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, SurveyPoint, Benchmark, FinalCorrectedElevation_ft) %>% + r_elevs_data <- r_elevs |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, SurveyPoint, Benchmark, FinalCorrectedElevation_ft) |> dplyr::rename(R_Elev_ft = FinalCorrectedElevation_ft) - survey_elevs_data <- survey_elevs %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedWaterSurfaceElevation_m, FieldCalculatedRM2Elevation_m, FieldCalculatedRM3Elevation_m) %>% + survey_elevs_data <- survey_elevs |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedWaterSurfaceElevation_m, FieldCalculatedRM2Elevation_m, FieldCalculatedRM3Elevation_m) |> tidyr::pivot_longer(cols = -c(SiteCode, SiteName, VisitDate, FieldSeason), names_to = "SurveyPoint", - values_to = "Survey_Elev_m") %>% - unique() %>% + values_to = "Survey_Elev_m") |> + unique() |> dplyr::mutate(SurveyPoint = dplyr::case_when(SurveyPoint == "FieldCalculatedWaterSurfaceElevation_m" ~ "WS", SurveyPoint == "FieldCalculatedRM2Elevation_m" ~ "RM2", SurveyPoint == "FieldCalculatedRM3Elevation_m" ~ "RM3", - TRUE ~ SurveyPoint)) %>% - dplyr::filter(!is.na(Survey_Elev_m)) %>% - dplyr::mutate(Survey_Elev_ft = Survey_Elev_m * 3.28084) %>% + TRUE ~ SurveyPoint)) |> + dplyr::filter(!is.na(Survey_Elev_m)) |> + dplyr::mutate(Survey_Elev_ft = Survey_Elev_m * 3.28084) |> dplyr::select(-c("Survey_Elev_m")) - elevs_data_joined <- r_elevs_data %>% - dplyr::inner_join(survey_elevs_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SurveyPoint")) %>% - dplyr::mutate(Elev_diff = round(as.numeric(format(R_Elev_ft - Survey_Elev_ft, scientific = FALSE)), 5)) %>% + elevs_data_joined <- r_elevs_data |> + dplyr::inner_join(survey_elevs_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SurveyPoint")) |> + dplyr::mutate(Elev_diff = round(as.numeric(format(R_Elev_ft - Survey_Elev_ft, scientific = FALSE)), 5)) |> dplyr::arrange(desc(abs(Elev_diff))) return(elevs_data_joined) @@ -357,45 +331,39 @@ qcElevationDiscrepancies <- function(park, site, field.season) { #' Check the difference between closure errors calculated in R with those calculated in the Survey123 app #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return Tibble +#' @return A tibble #' @export #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' qcStringSurveyElevations(conn) -#' qQcStringSurveyElevations(conn, site = c("GRBA_L_BAKR0", "GRBA_L_JHNS0"), field.season = "2021") -#' qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") -#' CloseDatabaseConnection(conn) +#' qcStringSurveyElevations() +#' qQcStringSurveyElevations(site = c("GRBA_L_BAKR0", "GRBA_L_JHNS0"), field.season = "2021") #' } qcClosureErrorDiscrepancies <- function(park, site, field.season) { r_elevs <- SurveyPointElevation(park = park, site = site, field.season = field.season) survey_elevs <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") - r_ce_data <- r_elevs %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, ClosureError_ft) %>% - dplyr::rename(R_CE_ft = ClosureError_ft) %>% - dplyr::mutate(R_CE_ft = round(as.numeric(format(R_CE_ft, scientific = FALSE)), 4)) %>% + r_ce_data <- r_elevs |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, ClosureError_ft) |> + dplyr::rename(R_CE_ft = ClosureError_ft) |> + dplyr::mutate(R_CE_ft = round(as.numeric(format(R_CE_ft, scientific = FALSE)), 4)) |> unique() - survey_ce_data <- survey_elevs %>% - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedClosureError) %>% - dplyr::rename(Survey_CE_ft = FieldCalculatedClosureError) %>% - unique() %>% - dplyr::mutate(Survey_CE_ft = round(as.numeric(format(Survey_CE_ft, scientific = FALSE)), 4)) %>% + survey_ce_data <- survey_elevs |> + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedClosureError) |> + dplyr::rename(Survey_CE_ft = FieldCalculatedClosureError) |> + unique() |> + dplyr::mutate(Survey_CE_ft = round(as.numeric(format(Survey_CE_ft, scientific = FALSE)), 4)) |> dplyr::filter(!is.na(Survey_CE_ft)) - ce_data_joined <- r_ce_data %>% - dplyr::inner_join(survey_ce_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) %>% - dplyr::mutate(CE_diff = round(as.numeric(format(R_CE_ft - Survey_CE_ft, scientific = FALSE)), 5)) %>% + ce_data_joined <- r_ce_data |> + dplyr::inner_join(survey_ce_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) |> + dplyr::mutate(CE_diff = round(as.numeric(format(R_CE_ft - Survey_CE_ft, scientific = FALSE)), 5)) |> dplyr::arrange(desc(abs(CE_diff))) return(ce_data_joined) @@ -411,14 +379,12 @@ qcClosureErrorDiscrepancies <- function(park, site, field.season) { #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' PlotBenchmarkElevation(conn) -#' PlotBenchmarkElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) -#' CloseDatabaseConnection(conn) +#' PlotBenchmarkElevation() +#' PlotBenchmarkElevation(site = "GRBA_L_DEAD0", plotly = TRUE) #' } PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { - lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) %>% - dplyr::filter(Benchmark != "Water Surface") %>% + lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + dplyr::filter(Benchmark != "Water Surface") |> tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") ptol_muted_6 <- c("#CC6677", "#332288", "#DDCC77", "#117733", "#88CCEE", "#882255") @@ -456,17 +422,15 @@ PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRU #' #' @examples #' \dontrun{ -#' conn <- OpenDatabaseConnection() -#' PlotLakeSurfaceElevation(conn) -#' PlotLakeSurfaceElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) -#' CloseDatabaseConnection(conn) +#' PlotLakeSurfaceElevation() +#' PlotLakeSurfaceElevation(site = "GRBA_L_DEAD0", plotly = TRUE) #' } PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { elev <- LakeSurfaceElevation(park = park, site = site, field.season = field.season) - elev %<>% - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName)) %>% - dplyr::relocate(FieldSeason, .after = VisitDate) %>% + elev <- elev |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName)) |> + dplyr::relocate(FieldSeason, .after = VisitDate) |> dplyr::filter((FieldSeason == "2018" & SurveyType == "Digital Level") | FieldSeason != "2018") plt <- FormatPlot(data = elev, diff --git a/R/utils.R b/R/utils.R index 3b6fc78..3c5d04d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -50,7 +50,7 @@ get_data <- function(data.name) { #' } OpenDatabaseConnection <- function(use.mojn.default = TRUE, drv = odbc::odbc(), ...) { if (use.mojn.default) { - params <- readr::read_csv("M:/MONITORING/StreamsLakes/Data/Database/ConnectFromR/stlk-database-conn.csv", col_types = "cccc", ) %>% + params <- readr::read_csv("M:/MONITORING/StreamsLakes/Data/Database/ConnectFromR/stlk-database-conn.csv", col_types = "cccc", ) |> as.list() params$drv <- drv my.pool <- do.call(pool::dbPool, params) @@ -269,8 +269,7 @@ GetAGOLColSpec <- function() { BMISpecies = readr::cols( SampleID = readr::col_integer(), CollectionDate = readr::col_date(), - SplitCount = readr::col_integer(), - LabCount = readr::col_double(), + LabCount = readr::col_integer(), BigRareCount = readr::col_integer(), Sample_ID = readr::col_double(), .default = readr::col_character() @@ -696,17 +695,14 @@ SaveDataToCsv <- function(conn, dest.folder, create.folders = FALSE, overwrite = #' Raw data dump #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Spring code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A list of dataframes containing raw streams and lakes data. +#' @return A list of dataframes containing raw streams and lakes data #' @export #' -GetRawData <- function(conn, path.to.data, park, site, field.season, data.source = "database") { +GetRawData <- function(park, site, field.season) { data.dump <- list() db.names <- names(GetColSpec()) bmi.names <- names(GetAGOLColSpec()) @@ -715,7 +711,7 @@ GetRawData <- function(conn, path.to.data, park, site, field.season, data.source data.names <- c(db.names, bmi.names, aq.names) for (data.name in data.names) { - tryCatch(data.dump[[data.name]] <- ReadAndFilterData(conn, path.to.data, park, site, field.season, data.source, data.name), + tryCatch(data.dump[[data.name]] <- ReadAndFilterData(path.to.data, park, site, field.season, data.name), error = function(e) { if (e$message == "Aquarius connection does not exist.") { warning(paste0("Cannot connect to Aquarius. ", data.name, " omitted from data.")) @@ -740,8 +736,8 @@ GetRawData <- function(conn, path.to.data, park, site, field.season, data.source #' GetSiteName <- function(conn, path.to.data, site.code, data.source = "database") { site <- ReadAndFilterData(conn, path.to.data, site = site.code, data.source = data.source, data.name = "Site") - site %<>% dplyr::select("SiteCode", "SiteName") %>% - unique() %>% + site %<>% dplyr::select("SiteCode", "SiteName") |> + unique() |> dplyr::filter(SiteCode == site.code) return(site$SiteName) @@ -924,6 +920,7 @@ expect_dataframe_equal <- function(result, expected, ignore_col_order = FALSE, i #' #' @return A list of data frames and metadata #' @export +#' fetchAndWrangleAGOL <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_HYDRO_BMI_Database/FeatureServer", calibration_url = "https://services1.arcgis.com/fBc8EJBxQRMcHlei/arcgis/rest/services/MOJN_Calibration_Database/FeatureServer", agol_username = "mojn_data", @@ -940,8 +937,8 @@ fetchAndWrangleAGOL <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBx raw_bmi$data <- lapply(raw_bmi$data, function(df) { df |> - dplyr::filter(SiteCode %in% c("GRBA_S_BAKR2", "GRBA_S_BAKR3", "GRBA_S_LHMN2", "GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1", "GRBA_S_SFBW1", "GRBA_S_SHNG1", "GRBA_S_SNKE4", "GRBA_S_STRW2")) - # dplyr::mutate(CollectionDate = as.Date("CollectionDateText", tz = "America/Los_Angeles")) + dplyr::filter(SiteCode %in% c("GRBA_S_BAKR2", "GRBA_S_BAKR3", "GRBA_S_LHMN2", "GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1", "GRBA_S_SFBW1", "GRBA_S_SHNG1", "GRBA_S_SNKE4", "GRBA_S_STRW2")) |> + dplyr::mutate(CollectionDate = as.Date(CollectionDateText, tz = "America/Los_Angeles")) }) # Import WQ calibration database @@ -962,7 +959,7 @@ fetchAndWrangleAGOL <- function(bmi_url = "https://services1.arcgis.com/fBc8EJBx #' ReadAGOL <- function(...) { #Placeholder until more STLK data beyond BMI are moved from SQL to AGOL - data <- fetchAndWrangleAGOL()$data # Change name of variable to bmi once there are more data + data <- fetchAndWrangleAGOL() # Change name of variable to bmi once there are more data # agol <- fetchAndWrangleAGOL()$data # data <- c(bmi, agol) @@ -980,7 +977,7 @@ ReadSqlDatabase <- function(...) { col.spec <- GetColSpec() conn <- OpenDatabaseConnection(...) data <- lapply(names(col.spec), function(data.name){ - df <- dplyr::tbl(conn$db, dbplyr::in_schema("analysis", data.name)) %>% + df <- dplyr::tbl(conn$db, dbplyr::in_schema("analysis", data.name)) |> dplyr::collect() return(df) }) @@ -1112,14 +1109,14 @@ LoadStreamsAndLakes <- function(data_path = c("database", "aquarius", # Tidy up the data data <- lapply(data, function(df) { - df %>% - dplyr::mutate_if(is.character, utf8::utf8_encode) %>% - dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") %>% # Trim leading and trailing whitespace - dplyr::mutate_if(is.character, dplyr::na_if, "") %>% # Replace empty strings with NA - dplyr::mutate_if(is.character, dplyr::na_if, "\\\\n") %>% # Replace newlines with NA - dplyr::mutate_if(is.numeric, dplyr::na_if, -9999) %>% # Replace -9999 or -999 with NA - dplyr::mutate_if(is.numeric, dplyr::na_if, -999) %>% - dplyr::mutate_if(is.character, dplyr::na_if, "NA") %>% # Replace "NA" strings with NA + df |> + dplyr::mutate_if(is.character, utf8::utf8_encode) |> + dplyr::mutate_if(is.character, trimws, whitespace = "[\\h\\v]") |> # Trim leading and trailing whitespace + dplyr::mutate_if(is.character, dplyr::na_if, "") |> # Replace empty strings with NA + dplyr::mutate_if(is.character, dplyr::na_if, "\\\\n") |> # Replace newlines with NA + dplyr::mutate_if(is.numeric, dplyr::na_if, -9999) |> # Replace -9999 or -999 with NA + dplyr::mutate_if(is.numeric, dplyr::na_if, -999) |> + dplyr::mutate_if(is.character, dplyr::na_if, "NA") |> # Replace "NA" strings with NA dplyr::mutate_if(is.character, stringr::str_replace_all, pattern = "[\\v|\\n]+", replacement = "; ") # Replace newlines with semicolons - reading certain newlines into R can cause problems }) diff --git a/R/wq-qc.R b/R/wq-qc.R index 97840ea..2eccdb4 100644 --- a/R/wq-qc.R +++ b/R/wq-qc.R @@ -1,14 +1,11 @@ #' Lake water quality sanity check #' @description Perform sanity check and compile list of potentially incorrect or outlier water quality values. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m, Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcLakeWqSanity <- function(park, site, field.season) { @@ -19,14 +16,11 @@ qcLakeWqSanity <- function(park, site, field.season) { #' Stream water quality sanity check #' @description Perform sanity check and compile list of potentially incorrect or outlier water quality values. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcStreamWqSanity <- function(park, site, field.season) { @@ -38,15 +32,12 @@ qcStreamWqSanity <- function(park, site, field.season) { #' Water quality sanity check #' @description Perform sanity check and compile list of potentially incorrect or outlier water quality values. This function is not exported; instead it is called by StreamQcWqSanity and LakeQcWqSanity #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' @param wq.type Either "stream" or "lake". Indicates whether to use stream or lake water quality data. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' qcWqSanity <- function(park, site, field.season, wq.type) { if (wq.type == "stream") { @@ -57,35 +48,35 @@ qcWqSanity <- function(park, site, field.season, wq.type) { stop("Invalid wq.type") } - temp.sanity <- wq.sanity.predata %>% - dplyr::filter(TemperatureMedian_C > 20) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") %>% + temp.sanity <- wq.sanity.predata |> + dplyr::filter(TemperatureMedian_C > 20) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") |> dplyr::rename(Median = TemperatureMedian_C, Flag = TemperatureFlag) - spcond.sanity <- wq.sanity.predata %>% - dplyr::filter(SpCondMedian_microS_per_cm > 1000) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") %>% + spcond.sanity <- wq.sanity.predata |> + dplyr::filter(SpCondMedian_microS_per_cm > 1000) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") |> dplyr::rename(Median = SpCondMedian_microS_per_cm, Flag = SpCondFlag) - ph.sanity <- wq.sanity.predata %>% - dplyr::filter(pHMedian > 10 | pHMedian < 6) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") %>% + ph.sanity <- wq.sanity.predata |> + dplyr::filter(pHMedian > 10 | pHMedian < 6) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") |> dplyr::rename(Median = pHMedian, Flag = pHFlag) - do.mgl.sanity <- wq.sanity.predata %>% - dplyr::filter(DOMedian_mg_per_L > 12) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") %>% + do.mgl.sanity <- wq.sanity.predata |> + dplyr::filter(DOMedian_mg_per_L > 12) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") |> dplyr::rename(Median = DOMedian_mg_per_L, Flag = DOFlag) if (wq.type == "lake") { - do.percent.sanity <- wq.sanity.predata %>% - dplyr::filter(DOMedian_percent > 110 | DOMedian_percent < 2) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") %>% + do.percent.sanity <- wq.sanity.predata |> + dplyr::filter(DOMedian_percent > 110 | DOMedian_percent < 2) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") |> dplyr::rename(Median = DOMedian_percent, Flag = DOFlag) wq.sanity <- rbind(temp.sanity, spcond.sanity, ph.sanity, do.percent.sanity, do.mgl.sanity) } else { @@ -97,55 +88,48 @@ qcWqSanity <- function(park, site, field.season, wq.type) { #' Compile list of lake water quality values that have data quality flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcLakeWqFlags <- function(park, site, field.season) { lake.flags <- qcWqFlags(park = park, site = site, field.season = field.season, wq.type = "lake") - lake.flags %<>% dplyr::filter(!is.na(Median)) + lake.flags <- lake.flags |> + dplyr::filter(!is.na(Median)) return(lake.flags) } #' Compile list of stream water quality values that have data quality flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcStreamWqFlags <- function(park, site, field.season) { stream.flags <- qcWqFlags(park = park, site = site, field.season = field.season, wq.type = "stream") - stream.flags %<>% dplyr::filter(!is.na(Median)) + stream.flags <- stream.flags |> + dplyr::filter(!is.na(Median)) return(stream.flags) } #' Compile list of water quality values that have data quality flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' @param wq.type Either "stream" or "lake". Indicates whether to use stream or lake water quality data. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' qcWqFlags <- function(park, site, field.season, wq.type) { if (wq.type == "stream") { @@ -156,35 +140,35 @@ qcWqFlags <- function(park, site, field.season, wq.type) { stop("Invalid wq.type") } - temp.flags <- wq.flags.predata %>% - dplyr::filter(TemperatureFlag %in% c("I", "W", "C")) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") %>% + temp.flags <- wq.flags.predata |> + dplyr::filter(TemperatureFlag %in% c("I", "W", "C")) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") |> dplyr::rename(Median = TemperatureMedian_C, Flag = TemperatureFlag) - spcond.flags <- wq.flags.predata %>% - dplyr::filter(SpCondFlag %in% c("I", "W", "C")) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") %>% + spcond.flags <- wq.flags.predata |> + dplyr::filter(SpCondFlag %in% c("I", "W", "C")) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") |> dplyr::rename(Median = SpCondMedian_microS_per_cm, Flag = SpCondFlag) - ph.flags <- wq.flags.predata %>% - dplyr::filter(pHFlag %in% c("I", "W", "C")) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") %>% + ph.flags <- wq.flags.predata |> + dplyr::filter(pHFlag %in% c("I", "W", "C")) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") |> dplyr::rename(Median = pHMedian, Flag = pHFlag) - do.mgl.flags <- wq.flags.predata %>% - dplyr::filter(DOFlag %in% c("I", "W", "C")) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") %>% + do.mgl.flags <- wq.flags.predata |> + dplyr::filter(DOFlag %in% c("I", "W", "C")) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") |> dplyr::rename(Median = DOMedian_mg_per_L, Flag = DOFlag) if (wq.type == "lake") { - do.percent.flags <- wq.flags.predata %>% - dplyr::filter(DOFlag %in% c("I", "W", "C")) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") %>% + do.percent.flags <- wq.flags.predata |> + dplyr::filter(DOFlag %in% c("I", "W", "C")) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") |> dplyr::rename(Median = DOMedian_percent, Flag = DOFlag) wq.flags <- rbind(temp.flags, spcond.flags, ph.flags, do.percent.flags, do.mgl.flags) } else { @@ -197,14 +181,11 @@ qcWqFlags <- function(park, site, field.season, wq.type) { #' Intermediate step used to clean lake water quality data for stats and plotting functions. #' @description Limit data to primary visits and exclude data with "W" and "C" flags. Omit DO <110% or <12 mg/L. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcLakeWqCleaned <- function(park, site, field.season) { @@ -215,14 +196,11 @@ qcLakeWqCleaned <- function(park, site, field.season) { #' Intermediate step used to clean stream water quality data for stats and plotting functions. #' @description Limit data to primary visits and exclude data with "W" and "C" flags. Omit DO <110% or <12 mg/L. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcStreamWqCleaned <- function(park, site, field.season) { @@ -232,15 +210,12 @@ qcStreamWqCleaned <- function(park, site, field.season) { #' Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". -#' @param data.source Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' @param wq.type Either "stream" or "lake". Indicates whether to use stream or lake water quality data. #' -#' @return A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +#' @return A tibble #' @export #' qcWqCleaned <- function(park, site, field.season, wq.type) { @@ -252,35 +227,35 @@ qcWqCleaned <- function(park, site, field.season, wq.type) { stop("Invalid wq.type") } - temp.sanity <- wq.sanity.predata %>% - dplyr::filter(VisitType == "Primary", !(TemperatureFlag %in% c("W", "C"))) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") %>% + temp.sanity <- wq.sanity.predata |> + dplyr::filter(VisitType == "Primary", !(TemperatureFlag %in% c("W", "C"))) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "TemperatureMedian_C", "TemperatureFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "Temperature", Units = "C", .after = "VisitType") |> dplyr::rename(Median = TemperatureMedian_C, Flag = TemperatureFlag) - spcond.sanity <- wq.sanity.predata %>% - dplyr::filter(VisitType == "Primary", !(SpCondFlag %in% c("W", "C"))) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") %>% + spcond.sanity <- wq.sanity.predata |> + dplyr::filter(VisitType == "Primary", !(SpCondFlag %in% c("W", "C"))) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "SpCondMedian_microS_per_cm", "SpCondFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "SpCond", Units = "uS/cm", .after = "VisitType") |> dplyr::rename(Median = SpCondMedian_microS_per_cm, Flag = SpCondFlag) - ph.sanity <- wq.sanity.predata %>% - dplyr::filter(VisitType == "Primary", !(pHFlag %in% c("W", "C"))) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") %>% + ph.sanity <- wq.sanity.predata |> + dplyr::filter(VisitType == "Primary", !(pHFlag %in% c("W", "C"))) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "pHMedian", "pHFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "pH", Units = "units", .after = "VisitType") |> dplyr::rename(Median = pHMedian, Flag = pHFlag) - do.mgl.sanity <- wq.sanity.predata %>% - dplyr::filter(VisitType == "Primary", !(DOFlag %in% c("W", "C")), DOMedian_mg_per_L < 12 | is.na(DOMedian_mg_per_L)) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") %>% + do.mgl.sanity <- wq.sanity.predata |> + dplyr::filter(VisitType == "Primary", !(DOFlag %in% c("W", "C")), DOMedian_mg_per_L < 12 | is.na(DOMedian_mg_per_L)) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_mg_per_L", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "mg/L", .after = "VisitType") |> dplyr::rename(Median = DOMedian_mg_per_L, Flag = DOFlag) if (wq.type == "lake") { - do.percent.sanity <- wq.sanity.predata %>% - dplyr::filter(VisitType == "Primary", !(DOFlag %in% c("W", "C")), DOMedian_percent < 110 | is.na(DOMedian_percent)) %>% - dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) %>% - tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") %>% + do.percent.sanity <- wq.sanity.predata |> + dplyr::filter(VisitType == "Primary", !(DOFlag %in% c("W", "C")), DOMedian_percent < 110 | is.na(DOMedian_percent)) |> + dplyr::select(all_of(c("Park", "FieldSeason", "SiteCode", "SampleFrame", "VisitDate", "VisitType", "DOMedian_percent", "DOFlag", "FlagNote")), any_of("MeasurementDepth_m")) |> + tibble::add_column(Parameter = "DO", Units = "%", .after = "VisitType") |> dplyr::rename(Median = DOMedian_percent, Flag = DOFlag) wq.sanity <- rbind(temp.sanity, spcond.sanity, ph.sanity, do.percent.sanity, do.mgl.sanity) } else { @@ -290,16 +265,13 @@ qcWqCleaned <- function(park, site, field.season, wq.type) { #' Generate lake pH depth profile plots. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". #' @param include.title Include plot title? Defaults to true. #' @param plotly Return an interactive plotly object instead of a ggplot object? Defaults to false. -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return Depth profile plot for lake water quality. +#' @return ggplot or plotly object #' @export #' WqPlotPHDepthProfile <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { @@ -321,7 +293,7 @@ WqPlotPHDepthProfile <- function(park, site, field.season, include.title = TRUE, #' @param plotly Return an interactive plotly object instead of a ggplot object? Defaults to false. #' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return Depth profile plot for lake water quality. +#' @return ggplot or plotly object #' @export #' WqPlotDODepthProfile <- function(units = "mg/L", park, site, field.season, include.title = TRUE, plotly = FALSE) { @@ -333,16 +305,13 @@ WqPlotDODepthProfile <- function(units = "mg/L", park, site, field.season, inclu #' Generate lake specific conductance depth profile plots. #' -#' @param conn Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}. -#' @param path.to.data The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}. #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". #' @param field.season Optional. Field season name to filter on, e.g. "2019". #' @param include.title Include plot title? Defaults to true. #' @param plotly Return an interactive plotly object instead of a ggplot object? Defaults to false. -#' @param data.source Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database. #' -#' @return Depth profile plot for lake water quality. +#' @return ggplot or plotly object #' @export #' WqPlotSpCondDepthProfile <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { @@ -374,12 +343,12 @@ WqPlotTemperatureDepthProfile <- function(park, site, field.season, include.titl #' @param param The water quality parameter to plot. One of "pH", "DO", "SpCond", or "Temperature". #' @param units Units of dissolved oxygen. Either "mg/L" or "%". Ignored if `param != "DO"`. #' -#' @return Depth profile plot for lake water quality. +#' @return ggplot or plotly object #' WqPlotDepthProfile <- function(param, units, park, site, field.season, include.title = TRUE, plotly = FALSE) { - wq <- qcLakeWqCleaned(param = param, units = units, park = park, site = site, field.season = field.season) %>% - dplyr::filter(tolower(Parameter) == tolower(param), !is.na(Median)) %>% + wq <- qcLakeWqCleaned(park = park, site = site, field.season = field.season) |> + dplyr::filter(tolower(Parameter) == tolower(param), !is.na(Median)) |> dplyr::rename(Depth_m = MeasurementDepth_m) # Filter on unit if looking at DO. If not DO, set units @@ -387,7 +356,8 @@ WqPlotDepthProfile <- function(param, units, park, site, field.season, include.t if (missing(units) | !(units %in% c("mg/L", "%"))) { stop("Please specify correct units for DO. Must be mg/L or %.") } - wq %<>% dplyr::filter(tolower(Units) == tolower(units)) + wq <- wq |> + dplyr::filter(tolower(Units) == tolower(units)) } else { units <- unique(wq$Units) } diff --git a/man/BMIDiversityMetricsPlot.Rd b/man/BMIDiversityMetricsPlot.Rd index 9609afd..5b11251 100644 --- a/man/BMIDiversityMetricsPlot.Rd +++ b/man/BMIDiversityMetricsPlot.Rd @@ -12,12 +12,6 @@ BMIDiversityMetricsPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/BMIFormatted.Rd b/man/BMIFormatted.Rd index 5febd08..b1ea75b 100644 --- a/man/BMIFormatted.Rd +++ b/man/BMIFormatted.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/bmi-qc.R \name{BMIFormatted} \alias{BMIFormatted} -\title{Intermediate step used to pivot BMI data to an even longer format for ease of plotting} +\title{Create additional filtering and labeling columns for ease of plotting} \usage{ BMIFormatted(park, site, field.season) } @@ -12,16 +12,10 @@ BMIFormatted(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble } \description{ -Intermediate step used to pivot BMI data to an even longer format for ease of plotting +Create additional filtering and labeling columns for ease of plotting } diff --git a/man/BMIFunctionalMetricsPlot.Rd b/man/BMIFunctionalMetricsPlot.Rd index 276de71..e693282 100644 --- a/man/BMIFunctionalMetricsPlot.Rd +++ b/man/BMIFunctionalMetricsPlot.Rd @@ -12,12 +12,6 @@ BMIFunctionalMetricsPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/BMIGeneralMetricsPlot.Rd b/man/BMIGeneralMetricsPlot.Rd index 8c50029..3ce38e2 100644 --- a/man/BMIGeneralMetricsPlot.Rd +++ b/man/BMIGeneralMetricsPlot.Rd @@ -12,12 +12,6 @@ BMIGeneralMetricsPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/BMILong.Rd b/man/BMILong.Rd deleted file mode 100644 index 9e73fd9..0000000 --- a/man/BMILong.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bmi-qc.R -\name{BMILong} -\alias{BMILong} -\title{Pivot BMI data to long format} -\usage{ -BMILong(park, site, field.season) -} -\arguments{ -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} -} -\value{ -A tibble -} -\description{ -Pivot BMI data to long format -} -\examples{ -\dontrun{ -c <- OpenDatabaseConnection -bmi_long <- BMILong(c) # Pivot all BMI data longer -bmi_long_mill <- BMILong(c, site = "GRBA_S_MILL1") # Pivot BMI data from Mill Creek -bmi_long_bakr_2015 <- BMILong(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") -CloseDatabaseConnection(c) -} -} diff --git a/man/BMIMetricsLong.Rd b/man/BMIMetricsLong.Rd new file mode 100644 index 0000000..8386020 --- /dev/null +++ b/man/BMIMetricsLong.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bmi-qc.R +\name{BMIMetricsLong} +\alias{BMIMetricsLong} +\title{Return BMI metrics data} +\usage{ +BMIMetricsLong(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR1".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A tibble +} +\description{ +Return BMI metrics data +} +\examples{ +\dontrun{ + BMIMetricsLong() + BMIMetricsLong(site = c("GRBA_S_MILL1", "GRBA_S_Pine1"), field.season = "2015") +} +} diff --git a/man/BMISensitivityMetricsPlot.Rd b/man/BMISensitivityMetricsPlot.Rd new file mode 100644 index 0000000..0655afc --- /dev/null +++ b/man/BMISensitivityMetricsPlot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bmi-qc.R +\name{BMISensitivityMetricsPlot} +\alias{BMISensitivityMetricsPlot} +\title{Plot tolerance-related richness and abundance metrics for each BMI sample.} +\usage{ +BMISensitivityMetricsPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot tolerance-related richness and abundance metrics for each BMI sample. +} diff --git a/man/BMISpecies.Rd b/man/BMISpecies.Rd new file mode 100644 index 0000000..dda1495 --- /dev/null +++ b/man/BMISpecies.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bmi-qc.R +\name{BMISpecies} +\alias{BMISpecies} +\title{Return BMI species data} +\usage{ +BMISpecies(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR1".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A tibble +} +\description{ +Return BMI species data +} +\examples{ +\dontrun{ + BMISpecies() + BMISpecies(site = c("GRBA_S_MILL1", "GRBA_S_Pine1"), field.season = "2015") +} +} diff --git a/man/BMITaxonomicMetricsPlot.Rd b/man/BMITaxonomicMetricsPlot.Rd index de5ddcc..47f48c8 100644 --- a/man/BMITaxonomicMetricsPlot.Rd +++ b/man/BMITaxonomicMetricsPlot.Rd @@ -12,12 +12,6 @@ BMITaxonomicMetricsPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object diff --git a/man/BMIToleranceMetricsPlot.Rd b/man/BMIToleranceMetricsPlot.Rd deleted file mode 100644 index 9561876..0000000 --- a/man/BMIToleranceMetricsPlot.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bmi-qc.R -\name{BMIToleranceMetricsPlot} -\alias{BMIToleranceMetricsPlot} -\title{Plot tolerance-related richness and abundance metrics for each BMI sample.} -\usage{ -BMIToleranceMetricsPlot(park, site, field.season) -} -\arguments{ -\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} - -\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} - -\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} -} -\value{ -A ggplot object -} -\description{ -Plot tolerance-related richness and abundance metrics for each BMI sample. -} diff --git a/man/ChannelCharacteristics.Rd b/man/ChannelCharacteristics.Rd index b09f534..f041d75 100644 --- a/man/ChannelCharacteristics.Rd +++ b/man/ChannelCharacteristics.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/bmi-qc.R \name{ChannelCharacteristics} \alias{ChannelCharacteristics} -\title{Filter channel characteristic data by primary visit type} +\title{Return a table of channel characteristics data} \usage{ ChannelCharacteristics(park, site, field.season) } @@ -12,24 +12,16 @@ ChannelCharacteristics(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, Transect, TransectSide, ChannelType, Substrate, Notes +A tibble } \description{ -Filter channel characteristic data by primary visit type +Return a table of channel characteristics data } \examples{ \dontrun{ -conn <- OpenDatabaseConnection -channel <- ChannelCharacteristics(conn) -channel_STRW2_2016 <- ChannelCharacteristics(conn, site = "GRBA_S_STRW2", field.season = "2016") -CloseDatabaseConnection(conn) + channel <- ChannelCharacteristics() + channel <- ChannelCharacteristics(site = "GRBA_S_STRW2", field.season = "2016") } } diff --git a/man/ChannelFLow.Rd b/man/ChannelFLow.Rd index 7db749e..5ef27b9 100644 --- a/man/ChannelFLow.Rd +++ b/man/ChannelFLow.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/bmi-qc.R -\name{ChannelFLow} -\alias{ChannelFLow} +\name{ChannelFlow} +\alias{ChannelFlow} \title{Rank channel flow type by count for each BMI sample} \usage{ -ChannelFLow(park, site, field.season) +ChannelFlow(park, site, field.season) } \arguments{ \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} @@ -12,24 +12,16 @@ ChannelFLow(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelFlow, Rank, Count +A tibble } \description{ Rank channel flow type by count for each BMI sample } \examples{ \dontrun{ -conn <- OpenDatabaseConnection -channel_flow <- ChannelFlow(conn) -channel_flow_STRW2_2016 <- ChannelFlow(conn, site = "GRBA_S_STRW2", field.season = "2016") -CloseDatabaseConnection(conn) + ChannelFlow() + ChannelFlow(site = "GRBA_S_STRW2", field.season = "2016") } } diff --git a/man/ChannelSubstrate.Rd b/man/ChannelSubstrate.Rd index e4b866e..eaf8788 100644 --- a/man/ChannelSubstrate.Rd +++ b/man/ChannelSubstrate.Rd @@ -12,12 +12,6 @@ ChannelSubstrate(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, ChannelFlow, Rank, Count @@ -27,9 +21,7 @@ Rank channel substrate type by count for each BMI sample } \examples{ \dontrun{ -conn <- OpenDatabaseConnection -channel_substrate <- ChannelSubstrate(conn) -channel_substrate_STRW2_2016 <- ChannelSubstrate(conn, site = "GRBA_S_STRW2", field.season = "2016") -CloseDatabaseConnection(conn) + ChannelSubstrate() + ChannelSubstrate(site = "GRBA_S_STRW2", field.season = "2016") } } diff --git a/man/ChemANC.Rd b/man/ChemANC.Rd index be70dea..6ce5890 100644 --- a/man/ChemANC.Rd +++ b/man/ChemANC.Rd @@ -12,12 +12,6 @@ ChemANC(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, SampleFrame, VisitDate, VisitType, SampleCollectionMethod, Characteristic, CharacteristicLabel, LabValue, ReportingGroup, SampleType, Flag, FlagNote, DPL, Unit @@ -27,9 +21,7 @@ Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -ChemANC(conn) -ChemANC(conn, site = "GRBA_L_DEAD0", field.season = "2018") -CloseDatabaseConnection(conn) +ChemANC() +ChemANC(site = "GRBA_L_DEAD0", field.season = "2018") } } diff --git a/man/ChemLakeANCPlot.Rd b/man/ChemLakeANCPlot.Rd index e7896cb..da35f51 100644 --- a/man/ChemLakeANCPlot.Rd +++ b/man/ChemLakeANCPlot.Rd @@ -12,12 +12,6 @@ ChemLakeANCPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object @@ -27,10 +21,8 @@ Plot acid neutralizing capacity (ANC) at lakes, and include EPA thresholds } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -ChemLakeANCPlot(conn) -ChemLakeANCPlot(conn, site = "GRBA_L_DEAD0") -CloseDatabaseConnection(conn) +ChemLakeANCPlot() +ChemLakeANCPlot(site = "GRBA_L_DEAD0") } } diff --git a/man/ChemStreamANCPlot.Rd b/man/ChemStreamANCPlot.Rd index 2da1cd8..6d06503 100644 --- a/man/ChemStreamANCPlot.Rd +++ b/man/ChemStreamANCPlot.Rd @@ -12,12 +12,6 @@ ChemStreamANCPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object @@ -27,9 +21,7 @@ Plot acid neutralizing capacity (ANC) at streams, and include EPA thresholds } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -ChemStreamANCPlot(conn) -ChemStreamANCPlot(conn, site = "GRBA_S_PINE1") -CloseDatabaseConnection(conn) +ChemStreamANCPlot() +ChemStreamANCPlot(site = "GRBA_S_PINE1") } } diff --git a/man/GetRawData.Rd b/man/GetRawData.Rd index 2256ce7..54a15c2 100644 --- a/man/GetRawData.Rd +++ b/man/GetRawData.Rd @@ -4,26 +4,19 @@ \alias{GetRawData} \title{Raw data dump} \usage{ -GetRawData( - conn, - path.to.data, - park, - site, - field.season, - data.source = "database" -) +GetRawData(park, site, field.season) } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} \item{site}{Optional. Spring code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} + \item{data.source}{Character string indicating whether to access data in the desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ diff --git a/man/LakeSurfaceElevation.Rd b/man/LakeSurfaceElevation.Rd index 4c00acd..1ffd820 100644 --- a/man/LakeSurfaceElevation.Rd +++ b/man/LakeSurfaceElevation.Rd @@ -21,10 +21,7 @@ Calculates lake level elevations } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - LakeSurfaceElevation(conn) - LakeSurfaceElevation(conn, site = "GRBA_L_BAKR0", field.season = "2019") - LakeSurfaceElevation(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + LakeSurfaceElevation() + LakeSurfaceElevation(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/LakeWqMedian.Rd b/man/LakeWqMedian.Rd index 0260db3..d729302 100644 --- a/man/LakeWqMedian.Rd +++ b/man/LakeWqMedian.Rd @@ -12,15 +12,9 @@ LakeWqMedian(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. +A tibble } \description{ Calculate median values for each water quality parameter for each lake visit. diff --git a/man/PlotBenchmarkElevation.Rd b/man/PlotBenchmarkElevation.Rd index 72fad83..726442f 100644 --- a/man/PlotBenchmarkElevation.Rd +++ b/man/PlotBenchmarkElevation.Rd @@ -31,9 +31,7 @@ Plot benchmark elevations over time } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -PlotBenchmarkElevation(conn) -PlotBenchmarkElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) -CloseDatabaseConnection(conn) +PlotBenchmarkElevation() +PlotBenchmarkElevation(site = "GRBA_L_DEAD0", plotly = TRUE) } } diff --git a/man/PlotLakeSurfaceElevation.Rd b/man/PlotLakeSurfaceElevation.Rd index 48eec0a..05593f6 100644 --- a/man/PlotLakeSurfaceElevation.Rd +++ b/man/PlotLakeSurfaceElevation.Rd @@ -31,9 +31,7 @@ Plot lake surface elevations over time } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -PlotLakeSurfaceElevation(conn) -PlotLakeSurfaceElevation(conn, site = "GRBA_L_DEAD0", plotly = TRUE) -CloseDatabaseConnection(conn) +PlotLakeSurfaceElevation() +PlotLakeSurfaceElevation(site = "GRBA_L_DEAD0", plotly = TRUE) } } diff --git a/man/StreamWqMedian.Rd b/man/StreamWqMedian.Rd index c44ffda..cf06962 100644 --- a/man/StreamWqMedian.Rd +++ b/man/StreamWqMedian.Rd @@ -12,15 +12,9 @@ StreamWqMedian(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for park, field season, site code, visit date, and the median values, flags, and counts for temperature, specific conductance, pH, and dissolved oxygen. +A tibble } \description{ Calculate median values for each water quality parameter for each stream visit. diff --git a/man/SurveyPointElevation.Rd b/man/SurveyPointElevation.Rd index f1b98c5..a415553 100644 --- a/man/SurveyPointElevation.Rd +++ b/man/SurveyPointElevation.Rd @@ -14,17 +14,14 @@ SurveyPointElevation(park, site, field.season) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason,VisitType, DPL, SurveyPoint, Benchmark, FinalCorrectedElevation_ft. +A tibble } \description{ Calculates mean elevations for each survey point type in a survey } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - SurveyPointElevation(conn) - SurveyPointElevation(conn, site = "GRBA_L_BAKR0", field.season = "2019") - SurveyPointElevation(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + SurveyPointElevation() + SurveyPointElevation(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/WqDailyMean.Rd b/man/WqDailyMean.Rd index 976335b..5cd12c9 100644 --- a/man/WqDailyMean.Rd +++ b/man/WqDailyMean.Rd @@ -12,24 +12,16 @@ WqDailyMean(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, SiteType, Date, FieldSeason, Temp_C, Temp_C_Grade, pH, pH_Grade, SpCond_uScm, SpCond_uScm_Grade, DO_pct, DO_pct_Grade, DO_mgL, DO_mgL_Grade +A tibble } \description{ Return summary of daily mean values (daily median values for pH) and grades for water quality parameters at streams. } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - WqDailyMean(conn) - WqDailyMean(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + WqDailyMean() + WqDailyMean(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/WqDailyMeanLong.Rd b/man/WqDailyMeanLong.Rd index e7d19e6..29a2997 100644 --- a/man/WqDailyMeanLong.Rd +++ b/man/WqDailyMeanLong.Rd @@ -14,16 +14,14 @@ WqDailyMeanLong(park, site, field.season) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, SampleFrame, FieldSeason, Date, Parameter, Units, Value, Grade. +A tibble } \description{ Calculate daily mean values (daily median values for pH) for water quality parameters at streams based on hourly data. Determine the most frequent data grade level for each day based on hourly data. Include only those dates with greater than 80\% completeness (greater than 19 hourly values). Long format for ease of plotting. } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - WqDailyMeanLong(conn) - WqDailyMeanLong(conn, site = "GRBA_S_LHMN1", field.season = c("2012", "2013", "2014", "2015")) - CloseDatabaseConnection(conn) + WqDailyMeanLong() + WqDailyMeanLong(site = "GRBA_S_LHMN1", field.season = c("2012", "2013", "2014", "2015")) } } diff --git a/man/WqPlotDODepthProfile.Rd b/man/WqPlotDODepthProfile.Rd index 9a7b4ef..d0a5f9c 100644 --- a/man/WqPlotDODepthProfile.Rd +++ b/man/WqPlotDODepthProfile.Rd @@ -33,7 +33,7 @@ WqPlotDODepthProfile( \item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -Depth profile plot for lake water quality. +ggplot or plotly object } \description{ Generate lake DO depth profile plots. diff --git a/man/WqPlotDepthProfile.Rd b/man/WqPlotDepthProfile.Rd index c4e9a4c..fe5e12a 100644 --- a/man/WqPlotDepthProfile.Rd +++ b/man/WqPlotDepthProfile.Rd @@ -30,7 +30,7 @@ WqPlotDepthProfile( \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} } \value{ -Depth profile plot for lake water quality. +ggplot or plotly object } \description{ Generate lake depth profile plots. diff --git a/man/WqPlotPHDepthProfile.Rd b/man/WqPlotPHDepthProfile.Rd index 395dd88..ed53320 100644 --- a/man/WqPlotPHDepthProfile.Rd +++ b/man/WqPlotPHDepthProfile.Rd @@ -22,15 +22,9 @@ WqPlotPHDepthProfile( \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -Depth profile plot for lake water quality. +ggplot or plotly object } \description{ Generate lake pH depth profile plots. diff --git a/man/WqPlotSpCondDepthProfile.Rd b/man/WqPlotSpCondDepthProfile.Rd index f947000..e700843 100644 --- a/man/WqPlotSpCondDepthProfile.Rd +++ b/man/WqPlotSpCondDepthProfile.Rd @@ -22,15 +22,9 @@ WqPlotSpCondDepthProfile( \item{include.title}{Include plot title? Defaults to true.} \item{plotly}{Return an interactive plotly object instead of a ggplot object? Defaults to false.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -Depth profile plot for lake water quality. +ggplot or plotly object } \description{ Generate lake specific conductance depth profile plots. diff --git a/man/qcBMIDiscrepancies.Rd b/man/qcBMIDiscrepancies.Rd index e390e25..71784b6 100644 --- a/man/qcBMIDiscrepancies.Rd +++ b/man/qcBMIDiscrepancies.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/bmi-qc.R \name{qcBMIDiscrepancies} \alias{qcBMIDiscrepancies} -\title{Check for discrepancies between taxa count and abundance} +\title{BROKEN! FIX! Check for discrepancies between taxa count and abundance} \usage{ qcBMIDiscrepancies(park, site, field.season) } @@ -12,25 +12,17 @@ qcBMIDiscrepancies(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupCount, TaxaGroupAbundance, LabNotes. +A tibble } \description{ -Check for discrepancies between taxa count and abundance +BROKEN! FIX! Check for discrepancies between taxa count and abundance } \examples{ \dontrun{ -c <- OpenDatabaseConnection -bmi_issues <- qcBMIDiscrepancies(c) # Get all instances of discrepancy between taxa count and abundance -bmi_issues_mill <- qcBMIDiscrepancies(c, site = "GRBA_S_MILL1") # Look at issues for Mill Creek only -bmi_issues_bakr_2015 <- qcBMIDiscrepancies(c, site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") # Look at issues for Baker Creek sites in 2015 -CloseDatabaseConnection(c) + qcBMIDiscrepancies() + qcBMIDiscrepancies(site = "GRBA_S_MILL1") + qcBMIDiscrepancies(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") } } diff --git a/man/qcBenchmarkElevation.Rd b/man/qcBenchmarkElevation.Rd index 9527aff..36a6622 100644 --- a/man/qcBenchmarkElevation.Rd +++ b/man/qcBenchmarkElevation.Rd @@ -16,17 +16,14 @@ qcBenchmarkElevation(park, site, field.season, sd_cutoff = NA) \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, Benchmark, MeanElevation_ft, StDevElevation_ft. +A tibble } \description{ Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcBenchmarkElevation(conn) - qcBenchmarkElevation(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) - qcBenchmarkElevation(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcBenchmarkElevation() + qcBenchmarkElevation(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) } } diff --git a/man/qcChemFieldBlanks.Rd b/man/qcChemFieldBlanks.Rd index 90eb3df..dbe4e8e 100644 --- a/man/qcChemFieldBlanks.Rd +++ b/man/qcChemFieldBlanks.Rd @@ -12,24 +12,16 @@ qcChemFieldBlanks(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, FieldBlank, RPD, RPDFLag. +A tibble } \description{ List all laboratory values from field blanks that exceed the minimum detection level (MDL) for that analyte. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemFieldBlanks(conn) -qcChemFieldBlanks(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemFieldBlanks() +qcChemFieldBlanks(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemFieldDupes.Rd b/man/qcChemFieldDupes.Rd index 784ab43..5b2d1e2 100644 --- a/man/qcChemFieldDupes.Rd +++ b/man/qcChemFieldDupes.Rd @@ -12,24 +12,16 @@ qcChemFieldDupes(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, FieldDuplicate, RPD, RPDFLag. +A tibble } \description{ Calculate the relative percent difference (RPD) for field duplicates, flag results that exceed the 30\% MQO threshold, and list all RPD values and flags. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemFieldDupes(conn) -qcChemFieldDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemFieldDupes() +qcChemFieldDupes(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemFlags.Rd b/man/qcChemFlags.Rd index 5627e36..6e7827e 100644 --- a/man/qcChemFlags.Rd +++ b/man/qcChemFlags.Rd @@ -12,24 +12,16 @@ qcChemFlags(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote. +A tibble } \description{ List all laboratory values that have an "Information," "Warning," or "Critical" flag. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemFlags(conn) -qcChemFlags(conn, site = c("GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemFlags() +qcChemFlags(site = c("GRBA_S_MILL1", "GRBA_S_PINE1", "GRBA_S_RDGE1"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemLabDupes.Rd b/man/qcChemLabDupes.Rd index bc598f2..b9370ef 100644 --- a/man/qcChemLabDupes.Rd +++ b/man/qcChemLabDupes.Rd @@ -12,24 +12,16 @@ qcChemLabDupes(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, Routine, LabDuplicate, LabTriplicate, RPD, RPD2, RPDFLag. +A tibble } \description{ Calculate the relative percent difference (RPD) for laboratory duplicates and triplicates, flag results that exceed the 30\% MQO threshold, and list all RPD values and flags. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemLabDupes(conn) -qcChemLabDupes(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemLabDupes() +qcChemLabDupes(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemMDL.Rd b/man/qcChemMDL.Rd index f1c994a..45e210a 100644 --- a/man/qcChemMDL.Rd +++ b/man/qcChemMDL.Rd @@ -27,9 +27,7 @@ List all routine laboratory values that are less than or equal to the minimum de } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemMDL(conn) -qcChemMDL(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemMDL() +qcChemMDL(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemML.Rd b/man/qcChemML.Rd index 919fb78..67bda9b 100644 --- a/man/qcChemML.Rd +++ b/man/qcChemML.Rd @@ -12,12 +12,6 @@ qcChemML(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, ML, MLFlag. @@ -27,9 +21,7 @@ List all routine laboratory values that are less than or equal to the minimum le } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemML(conn) -qcChemML(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemML() +qcChemML(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemNO3NO2.Rd b/man/qcChemNO3NO2.Rd index c47dabb..68fe201 100644 --- a/man/qcChemNO3NO2.Rd +++ b/man/qcChemNO3NO2.Rd @@ -12,24 +12,16 @@ qcChemNO3NO2(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTN, TDN, NO3NO2, NO3NO2vUTN, NO3NO2vTDN, NO3NO2Flag. +A tibble } \description{ List all routine samples where nitrate and nitrite (NO3NO2-N) values exceeded either total dissolved nitrogen (TDN) values or total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemNO3NO2(conn) -qcChemNO3NO2(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemNO3NO2() +qcChemNO3NO2(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemTDN.Rd b/man/qcChemTDN.Rd index 66e30f1..169507c 100644 --- a/man/qcChemTDN.Rd +++ b/man/qcChemTDN.Rd @@ -12,24 +12,16 @@ qcChemTDN(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTN, TDN, TDNvUTN, TDNFlag. +A tibble } \description{ List all routine samples where total dissolved nitrogen (TDN) values exceeded total nitrogen (UTN) values, and flag whether the discrepancy was within precision limits or outside of the expected error. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemTDN(conn) -qcChemTDN(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemTDN() +qcChemTDN(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcChemTDP.Rd b/man/qcChemTDP.Rd index 0bd5d62..56bdce3 100644 --- a/man/qcChemTDP.Rd +++ b/man/qcChemTDP.Rd @@ -12,24 +12,16 @@ qcChemTDP(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Unit, UTP, TDP, TDPvUTP, TDPFlag. +A tibble } \description{ List all routine samples where total dissolved phosphorous (TDP) values exceeded total phosphorus (UTP) values, and flag whether the discrepancy was within precision limits or outside of the expected error. } \examples{ \dontrun{ -conn <- OpenDatabaseConnection() -qcChemTDP(conn) -qcChemTDP(conn, site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) -CloseDatabaseConnection(conn) +qcChemTDP() +qcChemTDP(site = c("GRBA_L_DEAD0", "GRBA_L_JHNS0"), field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcClosureErrorDiscrepancies.Rd b/man/qcClosureErrorDiscrepancies.Rd index 5d70ded..e2a8b8b 100644 --- a/man/qcClosureErrorDiscrepancies.Rd +++ b/man/qcClosureErrorDiscrepancies.Rd @@ -12,25 +12,16 @@ qcClosureErrorDiscrepancies(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -Tibble +A tibble } \description{ Check the difference between closure errors calculated in R with those calculated in the Survey123 app } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyElevations(conn) - qQcStringSurveyElevations(conn, site = c("GRBA_L_BAKR0", "GRBA_L_JHNS0"), field.season = "2021") - qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcStringSurveyElevations() + qQcStringSurveyElevations(site = c("GRBA_L_BAKR0", "GRBA_L_JHNS0"), field.season = "2021") } } diff --git a/man/qcDPLCheck.Rd b/man/qcDPLCheck.Rd index f785c10..29e7c92 100644 --- a/man/qcDPLCheck.Rd +++ b/man/qcDPLCheck.Rd @@ -14,16 +14,14 @@ qcDPLCheck(park, site, field.season) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} } \value{ -A tibble with columns SiteCode, SiteName, VisitDate, FieldSeason, SampleFrame, VisitType, Visit.DPL, Chem.DPL, BMI.DPL, Channel.DPL, Clarity.DPL, LakeSurvey.DPL, LakeString.DPL, Xsection.DPL, TempC.DPL, pH.DPL, SpCond.DPL, DO.DPL +A tibble } \description{ Return list of site visits that have any data categorized as "Raw" or "Provisional" } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcDPLCheck(conn) - qcDPLCheck(conn, site = "GRBA_L_JHNS0", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcDPLCheck() + qcDPLCheck(site = "GRBA_L_JHNS0", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcElevationDiscrepancies.Rd b/man/qcElevationDiscrepancies.Rd index de214e7..42b2758 100644 --- a/man/qcElevationDiscrepancies.Rd +++ b/man/qcElevationDiscrepancies.Rd @@ -12,25 +12,16 @@ qcElevationDiscrepancies(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -Tibble +A tibble } \description{ Check the difference between benchmark and water surface elevations calculated in R with those calculated in the Survey123 app } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyElevations(conn) - qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2019", "2021")) - qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcStringSurveyElevations() + qQcStringSurveyElevations(site = "GRBA_L_BAKR0", field.season = c("2019", "2021")) } } diff --git a/man/qcLakeDryMeasurementsExist.Rd b/man/qcLakeDryMeasurementsExist.Rd index 29c3b19..2490aa1 100644 --- a/man/qcLakeDryMeasurementsExist.Rd +++ b/man/qcLakeDryMeasurementsExist.Rd @@ -12,25 +12,16 @@ qcLakeDryMeasurementsExist(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. +A tibble } \description{ List clarity records where lake is dry but clarity measurements exist } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcLakeDryMeasurementsExist(conn) - qcLakeDryMeasurementsExist(conn, site = "GRBA_L_BAKR0", field.season = "2019") - qcLakeDryMeasurementsExist(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcLakeDryMeasurementsExist() + qcLakeDryMeasurementsExist(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/qcLakeNotDryMeasurementsMissing.Rd b/man/qcLakeNotDryMeasurementsMissing.Rd index f7d1a92..cebc044 100644 --- a/man/qcLakeNotDryMeasurementsMissing.Rd +++ b/man/qcLakeNotDryMeasurementsMissing.Rd @@ -12,12 +12,6 @@ qcLakeNotDryMeasurementsMissing(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. @@ -27,10 +21,7 @@ List clarity records where lake is not dry but measurements are missing } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcLakeNotDryMeasurementsMissing(conn) - qcLakeNotDryMeasurementsMissing(conn, site = "GRBA_L_BAKR0", field.season = "2019") - qcLakeNotDryMeasurementsMissing(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcLakeNotDryMeasurementsMissing() + qcLakeNotDryMeasurementsMissing(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/qcLakeWqCleaned.Rd b/man/qcLakeWqCleaned.Rd index 142e9d3..fe6fba2 100644 --- a/man/qcLakeWqCleaned.Rd +++ b/man/qcLakeWqCleaned.Rd @@ -12,15 +12,9 @@ qcLakeWqCleaned(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Limit data to primary visits and exclude data with "W" and "C" flags. Omit DO <110\% or <12 mg/L. diff --git a/man/qcLakeWqFlags.Rd b/man/qcLakeWqFlags.Rd index fa30838..7663ab8 100644 --- a/man/qcLakeWqFlags.Rd +++ b/man/qcLakeWqFlags.Rd @@ -12,15 +12,9 @@ qcLakeWqFlags(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Compile list of lake water quality values that have data quality flags. diff --git a/man/qcLakeWqSanity.Rd b/man/qcLakeWqSanity.Rd index caadaf0..164f48d 100644 --- a/man/qcLakeWqSanity.Rd +++ b/man/qcLakeWqSanity.Rd @@ -12,15 +12,9 @@ qcLakeWqSanity(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m, Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Perform sanity check and compile list of potentially incorrect or outlier water quality values. diff --git a/man/qcNoAnnualVisit.Rd b/man/qcNoAnnualVisit.Rd index 4f0bff3..191b2a8 100644 --- a/man/qcNoAnnualVisit.Rd +++ b/man/qcNoAnnualVisit.Rd @@ -21,9 +21,7 @@ Return list of streams and lakes that were not visited for annual monitoring dur } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcNoAnnualVisit(conn) - qcNoAnnualVisit(conn, site = "GRBA_L_DEAD0", field.season = c("2012", "2013", "2014", "2015")) - CloseDatabaseConnection(conn) + qcNoAnnualVisit() + qcNoAnnualVisit(site = "GRBA_L_DEAD0", field.season = c("2012", "2013", "2014", "2015")) } } diff --git a/man/qcSecchiDepthMissing.Rd b/man/qcSecchiDepthMissing.Rd index 240aaac..0c13090 100644 --- a/man/qcSecchiDepthMissing.Rd +++ b/man/qcSecchiDepthMissing.Rd @@ -12,25 +12,16 @@ qcSecchiDepthMissing(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. +A tibble } \description{ List clarity records where secchi disk is not on bottom but secchi depth measurement is missing } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcDepthMissing(conn) - qcDepthMissing(conn, site = "GRBA_L_BAKR0", field.season = "2019") - qcDepthMissing(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcDepthMissing() + qcDepthMissing(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/qcSecchiGTDepth.Rd b/man/qcSecchiGTDepth.Rd index e107b20..155a0a2 100644 --- a/man/qcSecchiGTDepth.Rd +++ b/man/qcSecchiGTDepth.Rd @@ -12,12 +12,6 @@ qcSecchiGTDepth(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_DEAD0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, IsLakeDry, SurfaceCalm, OnBottom, DepthToBottom_m, SecchiDepth_m, VisitType, DPL. @@ -27,10 +21,7 @@ List secchi depth measurements that are greater than the recorded lake depth } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcSecchiGTDepth(conn) - qcSecchiGTDepth(conn, site = "GRBA_L_BAKR0", field.season = "2019") - qcSecchiGTDepth(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcSecchiGTDepth() + qcSecchiGTDepth(site = "GRBA_L_BAKR0", field.season = "2019") } } diff --git a/man/qcStreamWqCleaned.Rd b/man/qcStreamWqCleaned.Rd index ae85056..fb53ddb 100644 --- a/man/qcStreamWqCleaned.Rd +++ b/man/qcStreamWqCleaned.Rd @@ -12,15 +12,9 @@ qcStreamWqCleaned(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Limit data to primary visits and exclude data with "W" and "C" flags. Omit DO <110\% or <12 mg/L. diff --git a/man/qcStreamWqFlags.Rd b/man/qcStreamWqFlags.Rd index c9f85ed..52e0b6b 100644 --- a/man/qcStreamWqFlags.Rd +++ b/man/qcStreamWqFlags.Rd @@ -12,15 +12,9 @@ qcStreamWqFlags(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Compile list of stream water quality values that have data quality flags. diff --git a/man/qcStreamWqSanity.Rd b/man/qcStreamWqSanity.Rd index cf63150..c00d523 100644 --- a/man/qcStreamWqSanity.Rd +++ b/man/qcStreamWqSanity.Rd @@ -12,15 +12,9 @@ qcStreamWqSanity(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Perform sanity check and compile list of potentially incorrect or outlier water quality values. diff --git a/man/qcStringSurveyElevations.Rd b/man/qcStringSurveyElevations.Rd index ce9d48e..d35ba22 100644 --- a/man/qcStringSurveyElevations.Rd +++ b/man/qcStringSurveyElevations.Rd @@ -23,10 +23,7 @@ Calculates mean and standard deviation of string survey lake level elevations fo } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyElevations(conn) - qQcStringSurveyElevations(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) - qcStringSurveyElevations(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcStringSurveyElevations() + qQcStringSurveyElevations(site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) } } diff --git a/man/qcStringSurveyHeights.Rd b/man/qcStringSurveyHeights.Rd index fcfca84..ae458d8 100644 --- a/man/qcStringSurveyHeights.Rd +++ b/man/qcStringSurveyHeights.Rd @@ -16,17 +16,14 @@ qcStringSurveyHeights(park, site, field.season, sd_cutoff = NA) \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanHeight_ft, StDevHeight_ft +A tibble } \description{ Calculates mean and standard deviation of string survey heights for each benchmark } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcStringSurveyHeights(conn) - qcStringSurveyHeights(conn, site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) - qcStringSurveyHeights(path.to.data = "path/to/data", data.source = "local") - CloseDatabaseConnection(conn) + qcStringSurveyHeights() + qcStringSurveyHeights(site = "GRBA_L_BAKR0", field.season = c("2016", "2017")) } } diff --git a/man/qcWqCleaned.Rd b/man/qcWqCleaned.Rd index 143360f..4bfa9e2 100644 --- a/man/qcWqCleaned.Rd +++ b/man/qcWqCleaned.Rd @@ -14,15 +14,9 @@ qcWqCleaned(park, site, field.season, wq.type) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Intermediate step used to clean water quality data for stats and plotting functions. Limit data to primary visits, and exclude data with "W" and "C" flags. diff --git a/man/qcWqCompleteness.Rd b/man/qcWqCompleteness.Rd index ce427a4..e11c2a9 100644 --- a/man/qcWqCompleteness.Rd +++ b/man/qcWqCompleteness.Rd @@ -12,12 +12,6 @@ qcWqCompleteness(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble @@ -27,9 +21,7 @@ Calculate the number and percentage of days of data for each water quality param } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcWqCompleteness(conn) - qcWqCompleteness(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcWqCompleteness() + qcWqCompleteness(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcWqCompletenessPlot.Rd b/man/qcWqCompletenessPlot.Rd index 7531008..278cc89 100644 --- a/man/qcWqCompletenessPlot.Rd +++ b/man/qcWqCompletenessPlot.Rd @@ -12,12 +12,6 @@ qcWqCompletenessPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object @@ -27,9 +21,7 @@ Plot percent completeness for each water quality parameter for each stream for e } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcWqCompletenessPlot(conn) - qcWqCompletenessPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcWqCompletenessPlot() + qcWqCompletenessPlot(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcWqFlags.Rd b/man/qcWqFlags.Rd index 8ffb5e4..ed37b67 100644 --- a/man/qcWqFlags.Rd +++ b/man/qcWqFlags.Rd @@ -14,15 +14,9 @@ qcWqFlags(park, site, field.season, wq.type) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Compile list of water quality values that have data quality flags. diff --git a/man/qcWqGrades.Rd b/man/qcWqGrades.Rd index 4e64b72..94d016e 100644 --- a/man/qcWqGrades.Rd +++ b/man/qcWqGrades.Rd @@ -12,12 +12,6 @@ qcWqGrades(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble @@ -27,9 +21,7 @@ Calculate the percentage of data rated at each grade level for each water qualit } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcWqGrades(conn) - qcWqGrades(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcWqGrades() + qcWqGrades(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcWqGradesLong.Rd b/man/qcWqGradesLong.Rd index f937e24..4c70f99 100644 --- a/man/qcWqGradesLong.Rd +++ b/man/qcWqGradesLong.Rd @@ -12,12 +12,6 @@ qcWqGradesLong(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A tibble @@ -27,9 +21,7 @@ Calculate percentage of data rated at each grade level for each water quality pa } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcWqGradesLong(conn) - qcWqGradesLong(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcWqGradesLong() + qcWqGradesLong(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcWqGradesPlot.Rd b/man/qcWqGradesPlot.Rd index d859fda..0d50695 100644 --- a/man/qcWqGradesPlot.Rd +++ b/man/qcWqGradesPlot.Rd @@ -12,12 +12,6 @@ qcWqGradesPlot(park, site, field.season) \item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ A ggplot object @@ -27,9 +21,7 @@ Plot the percentage of data rated at each grade level for each water quality par } \examples{ \dontrun{ - conn <- OpenDatabaseConnection() - qcWqGradesPlot(conn) - qcWqGradesPlot(conn, site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) - CloseDatabaseConnection(conn) + qcWqGradesPlot() + qcWqGradesPlot(site = "GRBA_S_BAKR1", field.season = c("2018", "2019", "2020")) } } diff --git a/man/qcWqSanity.Rd b/man/qcWqSanity.Rd index 07b5e8c..5fb845b 100644 --- a/man/qcWqSanity.Rd +++ b/man/qcWqSanity.Rd @@ -14,15 +14,9 @@ qcWqSanity(park, site, field.season, wq.type) \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} \item{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the live database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A tibble with columns for Park, FieldSeason, SiteCode, VisitDate, MeasurementDepth_m (lake only), Parameter, Units, Median, Flag, and FlagNote. +A tibble } \description{ Perform sanity check and compile list of potentially incorrect or outlier water quality values. This function is not exported; instead it is called by StreamQcWqSanity and LakeQcWqSanity From 7d044e2516b5bbb4cf32f3d0ebc014dedc6954c6 Mon Sep 17 00:00:00 2001 From: Bailard Date: Thu, 9 May 2024 16:14:40 -0700 Subject: [PATCH 13/27] Changed the way Aquarius database connection is stored in the environment --- R/utils.R | 143 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 70 deletions(-) diff --git a/R/utils.R b/R/utils.R index 3c5d04d..ee789c3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -61,15 +61,18 @@ OpenDatabaseConnection <- function(use.mojn.default = TRUE, drv = odbc::odbc(), #Connect to Aquarius tryCatch({#fetchaquarius::connectToAquarius("aqreadonly", "aqreadonly") timeseries$connect("https://aquarius.nps.gov/aquarius", "aqreadonly", "aqreadonly") - aq <<- timeseries}, + assign(x = "aq", value = timeseries, envir = pkg_globals)}, + # aq <<- timeseries}, error = function(e) { - aq <<- NA + assign(x = "aq", value = NA, envir = pkg_globals) + # aq <<- NA warning(paste("Could not connect to Aquarius. Verify that you are on the NPS network and that Aquarius is not down.", "Error message:", e, sep = "\n")) } ) conn <- list(db = my.pool, - aquarius = aq) + aquarius = get(x = "aq", + envir = pkg_globals)) return(conn) } @@ -112,71 +115,71 @@ GetColSpec <- function() { DataStoreReferenceCode = readr::col_integer(), .default = readr::col_character() ), - # BMI = readr::cols( - # VisitDate = readr::col_date(), - # DateCollected = readr::col_date(), - # FieldSplit = readr::col_integer(), - # LabSplit = readr::col_double(), - # SampleArea_m2 = readr::col_double(), - # Abundance = readr::col_integer(), - # Richness = readr::col_integer(), - # DominantTaxaPercent = readr::col_double(), - # SplitCount = readr::col_integer(), - # FixedCount = readr::col_integer(), - # BigRareCount = readr::col_integer(), - # ShannonsDiversity = readr::col_double(), - # SimpsonsDiversity = readr::col_double(), - # Evenness = readr::col_double(), - # EPTTaxaCount = readr::col_integer(), - # EPTTaxaAbundance = readr::col_integer(), - # DominantFamilyAbundance = readr::col_integer(), - # DominantTaxaAbundance = readr::col_integer(), - # Hilsenhoff = readr::col_double(), - # IntolerantTaxaCount = readr::col_integer(), - # IntolerantTaxaAbundance = readr::col_integer(), - # TolerantTaxaCount = readr::col_integer(), - # TolerantTaxaAbundance = readr::col_integer(), - # USFSCommunityToleranceQuo = readr::col_integer(), - # ShredderTaxaCount = readr::col_integer(), - # ShredderAbundance = readr::col_integer(), - # ScraperTaxaCount = readr::col_integer(), - # ScraperAbundance = readr::col_integer(), - # CollectorFiltererCount = readr::col_integer(), - # CollectorFiltererAbundance = readr::col_integer(), - # CollectorGathererCount = readr::col_integer(), - # CollectorGathererAbundance = readr::col_integer(), - # PredatorTaxaCount = readr::col_integer(), - # PredatorTaxaAbundance = readr::col_integer(), - # ClingerTaxaCount = readr::col_integer(), - # LongLivedTaxa = readr::col_integer(), - # EphemeropteraTaxaCount = readr::col_integer(), - # EphemeropteraTaxaAbundance = readr::col_integer(), - # PlecopteraTaxa = readr::col_integer(), - # PlecopteraTaxaAbundance = readr::col_integer(), - # TrichopteraTaxaCount = readr::col_integer(), - # TrichopteraAbundance = readr::col_integer(), - # ColeopteraTaxaCount = readr::col_integer(), - # ColeopteraAbundance = readr::col_integer(), - # ElmidaeTaxaCount = readr::col_integer(), - # ElmidaeAbundance = readr::col_integer(), - # MegalopteraTaxaCount = readr::col_integer(), - # MegalopteraAbundance = readr::col_integer(), - # DipteraTaxaCount = readr::col_integer(), - # DipteraAbundance = readr::col_integer(), - # ChironomidaeTaxaCount = readr::col_integer(), - # ChironomidaeAbundance = readr::col_integer(), - # CrustaceaTaxaCount = readr::col_integer(), - # CrustaceaAbundance = readr::col_integer(), - # OligochaeteTaxaCount = readr::col_integer(), - # OligochaeteAbundance = readr::col_integer(), - # MolluscaTaxaCount = readr::col_integer(), - # MolluscaAbundance = readr::col_integer(), - # InsectTaxaCount = readr::col_integer(), - # InsectAbundance = readr::col_integer(), - # NonInsectTaxaCount = readr::col_integer(), - # NonInsectAbundance = readr::col_integer(), - # .default = readr::col_character() - # ), + BMI = readr::cols( + VisitDate = readr::col_date(), + DateCollected = readr::col_date(), + FieldSplit = readr::col_integer(), + LabSplit = readr::col_double(), + SampleArea_m2 = readr::col_double(), + Abundance = readr::col_integer(), + Richness = readr::col_integer(), + DominantTaxaPercent = readr::col_double(), + SplitCount = readr::col_integer(), + FixedCount = readr::col_integer(), + BigRareCount = readr::col_integer(), + ShannonsDiversity = readr::col_double(), + SimpsonsDiversity = readr::col_double(), + Evenness = readr::col_double(), + EPTTaxaCount = readr::col_integer(), + EPTTaxaAbundance = readr::col_integer(), + DominantFamilyAbundance = readr::col_integer(), + DominantTaxaAbundance = readr::col_integer(), + Hilsenhoff = readr::col_double(), + IntolerantTaxaCount = readr::col_integer(), + IntolerantTaxaAbundance = readr::col_integer(), + TolerantTaxaCount = readr::col_integer(), + TolerantTaxaAbundance = readr::col_integer(), + USFSCommunityToleranceQuo = readr::col_integer(), + ShredderTaxaCount = readr::col_integer(), + ShredderAbundance = readr::col_integer(), + ScraperTaxaCount = readr::col_integer(), + ScraperAbundance = readr::col_integer(), + CollectorFiltererCount = readr::col_integer(), + CollectorFiltererAbundance = readr::col_integer(), + CollectorGathererCount = readr::col_integer(), + CollectorGathererAbundance = readr::col_integer(), + PredatorTaxaCount = readr::col_integer(), + PredatorTaxaAbundance = readr::col_integer(), + ClingerTaxaCount = readr::col_integer(), + LongLivedTaxa = readr::col_integer(), + EphemeropteraTaxaCount = readr::col_integer(), + EphemeropteraTaxaAbundance = readr::col_integer(), + PlecopteraTaxa = readr::col_integer(), + PlecopteraTaxaAbundance = readr::col_integer(), + TrichopteraTaxaCount = readr::col_integer(), + TrichopteraAbundance = readr::col_integer(), + ColeopteraTaxaCount = readr::col_integer(), + ColeopteraAbundance = readr::col_integer(), + ElmidaeTaxaCount = readr::col_integer(), + ElmidaeAbundance = readr::col_integer(), + MegalopteraTaxaCount = readr::col_integer(), + MegalopteraAbundance = readr::col_integer(), + DipteraTaxaCount = readr::col_integer(), + DipteraAbundance = readr::col_integer(), + ChironomidaeTaxaCount = readr::col_integer(), + ChironomidaeAbundance = readr::col_integer(), + CrustaceaTaxaCount = readr::col_integer(), + CrustaceaAbundance = readr::col_integer(), + OligochaeteTaxaCount = readr::col_integer(), + OligochaeteAbundance = readr::col_integer(), + MolluscaTaxaCount = readr::col_integer(), + MolluscaAbundance = readr::col_integer(), + InsectTaxaCount = readr::col_integer(), + InsectAbundance = readr::col_integer(), + NonInsectTaxaCount = readr::col_integer(), + NonInsectAbundance = readr::col_integer(), + .default = readr::col_character() + ), Channel = readr::cols( VisitDate = readr::col_date(), .default = readr::col_character() @@ -734,8 +737,8 @@ GetRawData <- function(park, site, field.season) { #' @return The name of the site #' @export #' -GetSiteName <- function(conn, path.to.data, site.code, data.source = "database") { - site <- ReadAndFilterData(conn, path.to.data, site = site.code, data.source = data.source, data.name = "Site") +GetSiteName <- function(site.code, data.source = "database") { + site <- ReadAndFilterData(site = site.code, data.name = "Site") site %<>% dplyr::select("SiteCode", "SiteName") |> unique() |> dplyr::filter(SiteCode == site.code) From 91950b1a3f6e627eb710e2978ad6d923cef5f566 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 09:32:33 -0700 Subject: [PATCH 14/27] Added formatting function for plotting chem data; added new lake and stream nutrient and ion line plots --- R/chem-qc.R | 449 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 365 insertions(+), 84 deletions(-) diff --git a/R/chem-qc.R b/R/chem-qc.R index 14638a7..0a18eb7 100644 --- a/R/chem-qc.R +++ b/R/chem-qc.R @@ -364,7 +364,7 @@ qcChemML <- function(park, site, field.season) { } -#' Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) +#' Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) and fill missing years with NAs for ease of plotting #' #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". #' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". @@ -378,7 +378,7 @@ qcChemML <- function(park, site, field.season) { #' ChemANC() #' ChemANC(site = "GRBA_L_DEAD0", field.season = "2018") #' } -ChemANC <- function(park, site, field.season) { +ChemFormatted <- function(park, site, field.season) { chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") @@ -391,13 +391,22 @@ ChemANC <- function(park, site, field.season) { FlagNote = NA, LabValue = LabValue*20) - chem.anc <- rbind(chem, chem.anc.rows) + chem.joined <- rbind(chem, chem.anc.rows) |> + dplyr::mutate(Year = as.integer(FieldSeason)) - chem.anc <- chem.anc |> - dplyr::arrange(SiteCode, VisitDate, Characteristic) |> - dplyr::relocate(Unit, .before = "LabValue") + min.year <- min(chem.joined$Year) + max.year <- max(chem.joined$Year) - return(chem.anc) + chem.formatted <- chem.joined |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, Unit, ReportingGroup) |> + tidyr::complete(Year = tidyr::full_seq(min.year:max.year, 1)) |> + dplyr::ungroup() |> + dplyr::mutate(FieldSeason = dplyr::case_when(is.na(FieldSeason) ~ as.character(Year), + TRUE ~ FieldSeason)) |> + dplyr::select(SampleFrame, Park, SiteCode, SiteShort, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, ReportingGroup, Characteristic, CharacteristicLabel, Unit, LabValue, Flag, FlagNote, DPL) |> + dplyr::arrange(SiteCode, FieldSeason, Characteristic) + + return(chem.formatted) } @@ -418,17 +427,25 @@ ChemANC <- function(park, site, field.season) { #' ChemLakeANCPlot <- function(park, site, field.season) { - chem.anc <- ChemANC(park = park, site = site, field.season = field.season) + chem.anc <- ChemFormatted(park = park, site = site, field.season = field.season) chem.lake.anc <- chem.anc |> - dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC") + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) - chem.lake.anc.plot <- ggplot2::ggplot(chem.lake.anc, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic)) + + chem.lake.anc.plot <- ggplot2::ggplot(chem.lake.anc, + ggplot2::aes(x = FieldSeason, + y = LabValue, + color = SiteShort, + group = SiteShort)) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(~SiteShort, scales = "free_y") + + ggplot2::geom_line(linewidth = 1) + + # ggplot2::facet_grid(~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Acid Neutralizing Capacity (ueq/L)") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + ggplot2::labs(title = "Lake acid neutralizing capacity") + @@ -438,7 +455,8 @@ ChemLakeANCPlot <- function(park, site, field.season) { ggplot2::annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + ggplot2::annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + ggplot2::annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + - ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() return(chem.lake.anc.plot) @@ -460,27 +478,36 @@ ChemLakeANCPlot <- function(park, site, field.season) { #' } ChemStreamANCPlot <- function(park, site, field.season) { - chem.anc <- ChemANC(park = park, site = site, field.season = field.season) + chem.anc <- ChemFormatted(park = park, site = site, field.season = field.season) chem.stream.anc <- chem.anc |> - dplyr::filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC") + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + Characteristic == "ANC") thresholds <- data.frame(yintercept = c(20, 50, 100, 200), Lines = c("Acute", "Severe", "Elevated", "Moderately Acidic")) - chem.stream.anc.plot <- ggplot2::ggplot(chem.stream.anc, ggplot2::aes(x = FieldSeason, y = LabValue, group = Characteristic)) + + chem.stream.anc.plot <- ggplot2::ggplot(chem.stream.anc, + ggplot2::aes(x = FieldSeason, + y = LabValue, + color = SiteShort, + group = SiteShort)) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(~SiteShort, scales = "free_y") + + ggplot2::geom_line(linewidth = 1) + + # ggplot2::facet_grid(~SiteShort, scales = "free_y") + ggplot2::ylab(label = "Acid Neutralizing Capacity (ueq/L)") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + - ggplot2::labs(title = "Lake acid neutralizing capacity") + + ggplot2::labs(title = "Stream acid neutralizing capacity") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + ggplot2::geom_hline(yintercept = c(20, 50, 100, 200), linetype = "dashed", color = "gray 20") + ggplot2::annotate("text", x = "2012", y = 200, label = "Moderate", vjust = 1) + ggplot2::annotate("text", x = "2012", y = 100, label = "Elevated", vjust = 1) + ggplot2::annotate("text", x = "2012", y = 50, label = "Severe", vjust = 1) + ggplot2::annotate("text", x = "2012", y = 20, label = "Acute", vjust = 1) + - ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() return(chem.stream.anc.plot) @@ -496,35 +523,98 @@ ChemStreamANCPlot <- function(park, site, field.season) { #' ChemLakeNutrientPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) lake.nut <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + ReportingGroup == "Nutrient") |> + dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", + ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", + ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) + lake.nut$Nutrient_f = factor(lake.nut$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) lake.nut$Characteristic_f = factor(lake.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) lake.nut.plot <- ggplot2::ggplot(lake.nut, ggplot2::aes(x = FieldSeason, y = LabValue, - group = Characteristic, - text = paste0("Field Season: ", FieldSeason, "
", - "Lab Value: ", LabValue, "
", - "Parameter: ", Characteristic_f))) + + color = Characteristic_f, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Nutrient_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + - ggplot2::labs(title = "Lake nutrient concentrations") + + ggplot2::labs(title = "Lake nutrient concentrations", + x = "Field Season", + y = "Concentration (mg/L)", + color = "Nutrient") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + - ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::scale_color_manual(values = c("midnightblue", "royalblue1", "lightskyblue", "firebrick4", "lightpink2", "goldenrod")) + + ggplot2::theme(legend.position = "bottom") return(lake.nut.plot) } +#' Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets. +#' +#' @inheritParams ReadAndFilterData +#' +#' @return A ggplot object +#' @export +#' +ChemLakeNutrientSplitPlot <- function(park, site, field.season) { + + chem <- ChemFormatted(park = park, site = site, field.season = field.season) + + lake.nut <- chem |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + ReportingGroup == "Nutrient") |> + dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", + ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", + ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) + + lake.nut$Nutrient_f = factor(lake.nut$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) + lake.nut$Characteristic_f = factor(lake.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) + + lake.nut.plot <- ggplot2::ggplot(lake.nut, + ggplot2::aes(x = FieldSeason, + y = LabValue, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + + ggplot2::geom_point() + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Characteristic_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake nutrient concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + return(lake.nut.plot) + +} + + #' Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP) concentration data as overlapping bar plots for all parks and field seasons. #' #' @inheritParams ReadAndFilterData @@ -534,11 +624,14 @@ ChemLakeNutrientPlot <- function(park, site, field.season) { #' ChemLakeNutrientBarPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) lake.nut.bar <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Nutrient") |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + ReportingGroup == "Nutrient") |> dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) @@ -547,7 +640,7 @@ ChemLakeNutrientBarPlot <- function(park, site, field.season) { lake.nut.bar$Characteristic_f = factor(lake.nut.bar$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) lake.nut.bar <- lake.nut.bar |> - dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), desc(Characteristic_f))) |> + dplyr::arrange(match(Characteristic_f, c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC"), dplyr::desc(Characteristic_f))) |> dplyr::filter(Characteristic != "DOC") lake.nut.bar.plot <- ggplot2::ggplot(lake.nut.bar, ggplot2::aes(x = FieldSeason, @@ -563,7 +656,7 @@ ChemLakeNutrientBarPlot <- function(park, site, field.season) { ggplot2::labs(title = "Lake nutrient concentrations", fill = "Nutrient") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + - ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) + ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightskyblue", "firebrick4", "lightpink2")) return(lake.nut.bar.plot) @@ -579,35 +672,97 @@ ChemLakeNutrientBarPlot <- function(park, site, field.season) { #' ChemLakeIonPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) lake.ion <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Lake", ReportingGroup == "Ion", - Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) - - lake.ion$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + ReportingGroup == "Ion", + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S")) |> + dplyr::mutate(Ion = ifelse(Characteristic %in% c("Na", "Mg", "K", "Ca"), "Cation", + ifelse(Characteristic %in% c("Cl", "SO4-S"), "Anion", NA))) + + lake.ion$Ion_f = factor(lake.ion$Ion, levels = c("Cation", "Anion")) + lake.ion$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl")) lake.ion.plot <- ggplot2::ggplot(lake.ion, ggplot2::aes(x = FieldSeason, y = LabValue, - group = Characteristic, - text = paste0("Field Season: ", FieldSeason, "
", - "Lab Value: ", LabValue, "
", - "Parameter: ", Characteristic_f))) + + color = Characteristic_f, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(#rows = ggplot2::vars(Ion_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + - ggplot2::labs(title = "Lake ion concentrations") + + ggplot2::labs(title = "Lake ion concentrations", + x = "Field Season", + y = "Concentration (mg/L)", + color = "Ion") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + - ggplot2:: scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2:: scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() + + ggplot2::theme(legend.position = "bottom") return(lake.ion.plot) } +#' Plot lake ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets. +#' +#' @inheritParams ReadAndFilterData +#' +#' @return A ggplot object +#' @export +#' +ChemLakeIonSplitPlot <- function(park, site, field.season) { + + chem <- ChemFormatted(park = park, site = site, field.season = field.season) + + lake.ion <- chem |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("STLL0s")), + SampleFrame == "Lake", + ReportingGroup == "Ion", + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S")) |> + dplyr::mutate(Ion = ifelse(Characteristic %in% c("Na", "Mg", "K", "Ca"), "Cation", + ifelse(Characteristic %in% c("Cl", "SO4-S"), "Anion", NA))) + + lake.ion$Ion_f = factor(lake.ion$Ion, levels = c("Cation", "Anion")) + lake.ion$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl")) + + lake.ion.plot <- ggplot2::ggplot(lake.ion, ggplot2::aes(x = FieldSeason, + y = LabValue, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + + ggplot2::geom_point() + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Characteristic_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Lake ion concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2:: scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() + + return(lake.ion.plot) + +} + + #' Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons. #' #' @inheritParams ReadAndFilterData @@ -617,34 +772,96 @@ ChemLakeIonPlot <- function(park, site, field.season) { #' ChemStreamNutrientPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) stream.nut <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) - + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + ReportingGroup == "Nutrient") |> + dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", + ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", + ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) + + stream.nut$Nutrient_f = factor(stream.nut$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) stream.nut$Characteristic_f = factor(stream.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) stream.nut.plot <- ggplot2::ggplot(stream.nut, ggplot2::aes(x = FieldSeason, y = LabValue, - group = Characteristic, - text = paste0("Field Season: ", FieldSeason, "
", - "Lab Value: ", LabValue, "
", - "Parameter: ", Characteristic_f))) + + color = Characteristic_f, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Nutrient_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + - ggplot2::labs(title = "Stream nutrient concentrations") + + ggplot2::labs(title = "Stream nutrient concentrations", + x = "Field Season", + y = "Concentration (mg/L)", + color = "Nutrient") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + - ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + ggplot2::scale_color_manual(values = c("midnightblue", "royalblue1", "lightskyblue", "firebrick4", "lightpink2", "goldenrod")) + + ggplot2::theme(legend.position = "bottom") return(stream.nut.plot) } +#' Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets. +#' +#' @inheritParams ReadAndFilterData +#' +#' @return A ggplot object +#' @export +#' +ChemStreamNutrientSplitPlot <- function(park, site, field.season) { + + chem <- ChemFormatted(park = park, site = site, field.season = field.season) + + stream.nut <- chem |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + ReportingGroup == "Nutrient") |> + dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", + ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", + ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) + + stream.nut$Nutrient_f = factor(stream.nut$Nutrient, levels = c("Nitrogen", "Phosphorus", "Carbon")) + stream.nut$Characteristic_f = factor(stream.nut$Characteristic, levels = c("UTN", "TDN", "NO3NO2-N", "UTP", "TDP", "DOC")) + + stream.nut.plot <- ggplot2::ggplot(stream.nut, ggplot2::aes(x = FieldSeason, + y = LabValue, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + + ggplot2::geom_point() + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Characteristic_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Stream nutrient concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + return(stream.nut.plot) + +} + + #' Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP) concentration data as overlapping bar plots for all parks and field seasons. #' #' @inheritParams ReadAndFilterData @@ -653,11 +870,14 @@ ChemStreamNutrientPlot <- function(park, site, field.season) { #' @export #' ChemStreamNutrientBarPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) stream.nut.bar <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Nutrient", SiteShort != "BAKR2") |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + ReportingGroup == "Nutrient") |> dplyr::mutate(Nutrient = ifelse(Characteristic %in% c("UTN", "TDN", "NO3NO2-N"), "Nitrogen", ifelse(Characteristic %in% c("UTP", "TDP"), "Phosphorus", ifelse(Characteristic %in% c("DOC"), "Carbon", NA)))) @@ -682,7 +902,7 @@ ChemStreamNutrientBarPlot <- function(park, site, field.season) { ggplot2::labs(title = "Stream nutrient concentrations", fill = "Nutrient") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + - ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightblue", "darkred", "pink")) + ggplot2::scale_fill_manual(values = c("midnightblue", "royalblue1", "lightskyblue", "firebrick4", "lightpink2")) return(stream.nut.bar.plot) @@ -697,30 +917,91 @@ ChemStreamNutrientBarPlot <- function(park, site, field.season) { #' ChemStreamIonPlot <- function(park, site, field.season) { - chem <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Chemistry") + chem <- ChemFormatted(park = park, site = site, field.season = field.season) stream.ion <- chem |> - dplyr::filter(SampleType == "Routine", VisitType == "Primary", SampleFrame == "Stream", ReportingGroup == "Ion", SiteShort != "BAKR2", - Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S", "ALK2")) |> - tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, SampleFrame, Characteristic, CharacteristicLabel, ReportingGroup)) - - stream.ion$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2")) + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + ReportingGroup == "Ion", + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S")) |> + dplyr::mutate(Ion = ifelse(Characteristic %in% c("Na", "Mg", "K", "Ca"), "Cation", + ifelse(Characteristic %in% c("Cl", "SO4-S"), "Anion", NA))) + + stream.ion$Ion_f = factor(stream.ion$Ion, levels = c("Cation", "Anion")) + stream.ion$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl")) stream.ion.plot <- ggplot2::ggplot(stream.ion, ggplot2::aes(x = FieldSeason, y = LabValue, - group = Characteristic, - text = paste0("Field Season: ", FieldSeason, "
", - "Lab Value: ", LabValue, "
", - "Parameter: ", Characteristic_f))) + + color = Characteristic_f, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + ggplot2::geom_point() + - ggplot2::geom_line() + - ggplot2::facet_grid(Characteristic_f~SiteShort, scales = "free_y") + - ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(#rows = ggplot2::vars(Ion), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + - ggplot2::labs(title = "Stream ion concentrations") + + ggplot2::labs(title = "Stream ion concentrations", + x = "Field Season", + y = "Concentration (mg/L)", + color = "Ion") + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + - ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() + + ggplot2::theme(legend.position = "bottom") return(stream.ion.plot) } + +#' Plot stream ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets. +#' +#' @inheritParams ReadAndFilterData +#' +#' @return A ggplot object +#' @export +#' +ChemStreamIonSplitPlot <- function(park, site, field.season) { + + chem <- ChemFormatted(park = park, site = site, field.season = field.season) + + stream.ion <- chem |> + dplyr::filter(VisitType %in% c("Primary") | is.na(VisitType), + SampleType %in% c("Routine") | is.na(SampleType), + !(SiteShort %in% c("BAKR2", "LHMN1")), + SampleFrame == "Stream", + ReportingGroup == "Ion", + Characteristic %in% c("Na", "Mg", "K", "Ca", "Cl", "SO4-S")) |> + dplyr::mutate(Ion = ifelse(Characteristic %in% c("Na", "Mg", "K", "Ca"), "Cation", + ifelse(Characteristic %in% c("Cl", "SO4-S"), "Anion", NA))) + + stream.ion$Ion_f = factor(stream.ion$Ion, levels = c("Cation", "Anion")) + stream.ion$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl")) + + stream.ion.plot <- ggplot2::ggplot(stream.ion, ggplot2::aes(x = FieldSeason, + y = LabValue, + # color = Characteristic_f, + group = Characteristic_f, + text = paste0("Site Name: ", SiteName, "
", + "Field Season: ", FieldSeason, "
", + "Parameter: ", Characteristic_f, "
", + "Lab Value: ", LabValue))) + + ggplot2::geom_point() + + ggplot2::geom_line(linewidth = 1) + + ggplot2::facet_grid(rows = ggplot2::vars(Characteristic_f), + cols = ggplot2::vars(SiteShort), + scales = "free_y") + + ggplot2::ylab(label = "Concentration (mg/L)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) + + ggplot2::labs(title = "Stream ion concentrations") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + return(stream.ion.plot) + +} From 50325c16d27b8ae066bffb6fffff872b34407f21 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 09:33:36 -0700 Subject: [PATCH 15/27] Added function to compare deprecated to recent data from BugLab --- R/bmi-qc.R | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/R/bmi-qc.R b/R/bmi-qc.R index d8b12aa..1015d8d 100644 --- a/R/bmi-qc.R +++ b/R/bmi-qc.R @@ -15,13 +15,13 @@ BMIMetricsLong <- function(park, site, field.season) { metrics <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIMetrics") visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIVisit") - meta <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") + meta <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") # Delete once VisitType is added to BMIVisit table - meta <- meta |> + meta <- meta |> # Delete once VisitType is added to BMIVisit table dplyr::select(SiteCode, VisitDate, SiteShort, VisitType) |> unique() - visit <- visit |> + visit <- visit |> # Add VisitType to selected columns once added to BMIVisit table in AGOL dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) |> dplyr::rename(VisitDate = CollectionDate) |> unique() @@ -478,3 +478,104 @@ BMITaxonomicMetricsPlot <- function(park, site, field.season) { return(bmi.tax.plot) } + + +#' Pivot BMI data to long format (Deprecated data! Use for QC purposes only) +#' +#' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". +#' @param field.season Optional. Field season name to filter on, e.g. "2019". +#' +#' @return A tibble +#' @export +#' +#' @examples +#' \dontrun{ +#' BMILong() +#' BMILong(site = "GRBA_S_MILL1") +#' BMILong(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") +#' } +BMILong <- function(park, site, field.season) { + bmi <- ReadAndFilterData(data.name = "BMI") |> + dplyr::rename(AnalysisType = SampleType, + SamplerType = SampleCollectionMethod, + SampleID = LabSampleNumber, + Area = SampleArea_m2) |> + dplyr::select(-c(DPL, BMIMethod, DateCollected, LabNotes, FieldNotes, FixedCount, BigRareCount, DominantFamily, DominantTaxa, LabName)) |> + dplyr::mutate(Laboratory = "NAMC", + Project = "STLK", + Delivery = "Deprecated") |> + dplyr::relocate(Delivery, Laboratory, SampleID, Project, Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) |> + dplyr::mutate(DominantFamily = DominantFamilyAbundance/Abundance) |> + tidyr::pivot_longer(cols = Abundance:DominantFamily, names_to = "Attribute", values_to = "Value") |> + dplyr::mutate(Attribute = dplyr::case_when(Attribute == "PlecopteraTaxa" ~ "PlecopteraTaxaCount", + Attribute == "LongLivedTaxa" ~ "LongLivedTaxaCount", + Attribute == "Richness" ~ "TotalCount", + Attribute == "Abundance" ~ "TotalAbundance", + Attribute == "DominantTaxa" ~ "DominantTaxon", + Attribute == "InsectTaxaCount" ~ "InsectaTaxaCount", + Attribute == "InsectAbundance" ~ "InsectaAbundance", + Attribute == "DominantTaxaAbundance" ~ "DominantTaxonAbundance", + Attribute == "DominantTaxaPercent" ~ "DominantTaxonPercent", + TRUE ~ Attribute)) |> + dplyr::mutate(Metric = dplyr::case_when(grepl("Count", Attribute) ~ "Richness", + grepl("Abundance", Attribute) ~ "Density", + grepl("Hilsenhoff|Shannons|Simpsons|Evenness|USFS", Attribute) ~ "Index", + grepl("DominantFamily", Attribute) ~ "Fraction", + grepl("DominantTaxon", Attribute) ~ "Fraction", + TRUE ~ as.character(Attribute))) |> + dplyr::mutate(Category = dplyr::case_when(Attribute %in% c("TotalCount") ~ "Overall", + Attribute %in% c("TotalAbundance") ~ "Overall", + grepl("Shredder|Scraper|Collector|Predator", Attribute) ~ "Functional Feeding Group", + grepl("Clinger", Attribute) ~ "Habitat", + grepl("LongLived|Intolerant|Tolerant", Attribute) ~ "Sensitivity", + grepl("Insect|Ephemeroptera|Plecoptera|Trichoptera|Coleoptera|Elmidae|Diptera|Chironomidae|Megaloptera|Crustacea|NonInsect|Oligochaete|Mollusca", Attribute) ~ "Taxa Group", + grepl("DominantFamily", Attribute) ~ "Dominant Family", + grepl("DominantTaxon", Attribute) ~ "Dominant Taxon", + grepl("Hilsenhoff", Attribute) ~ "Hilsenhoff", + grepl("Shannons", Attribute) ~ "Shannons", + grepl("Simpsons", Attribute) ~ "Simpsons", + grepl("Evenness", Attribute) ~ "Evenness", + grepl("USFS", Attribute) ~ "USFS Community Tolerance Quotient", + TRUE ~ as.character(Attribute))) |> + dplyr::mutate(Type = dplyr::case_when(grepl("CollectorFilterer", Attribute) ~ "Collector Filterer", + grepl("CollectorGatherer", Attribute) ~ "Collector Gatherer", + grepl("Scraper", Attribute) ~ "Scraper", + grepl("Shredder", Attribute) ~ "Shredder", + grepl("Parasite", Attribute) ~ "Parasite", + grepl("Predator", Attribute) ~ "Predator", + grepl("PiercerHerbivore", Attribute) ~ "Piercer Herbivore", + grepl("Clinger", Attribute) ~ "Clinger", + grepl("Planktonic", Attribute) ~ "Planktonic", + grepl("Skater", Attribute) ~ "Skater", + grepl("Climber", Attribute) ~ "Climber", + grepl("Crawler", Attribute) ~ "Crawler", + grepl("Swimmer", Attribute) ~ "Swimmer", + grepl("Burrower", Attribute) ~ "Burrower", + grepl("Sprawler", Attribute) ~ "Sprawler", + grepl("LongLived", Attribute) ~ "Long Lived", + grepl("Intolerant", Attribute) ~ "Intolerant", + grepl("Tolerant", Attribute) ~ "Tolerant", + grepl("Insecta", Attribute) ~ "Insecta", + grepl("Ephemeroptera", Attribute) ~ "Ephemeroptera", + grepl("Plecoptera", Attribute) ~ "Plecoptera", + grepl("Trichoptera", Attribute) ~ "Trichoptera", + grepl("Coleoptera", Attribute) ~ "Coleoptera", + grepl("Elmidae", Attribute) ~ "Elmidae", + grepl("Diptera", Attribute) ~ "Diptera", + grepl("Chironomidae", Attribute) ~ "Chironomidae", + grepl("Megaloptera", Attribute) ~ "Megaloptera", + grepl("Crustacea", Attribute) ~ "Crustacea", + grepl("NonInsect", Attribute) ~ "NonInsects", + grepl("Oligochaete", Attribute) ~ "Oligochaeta", + grepl("Mollusca", Attribute) ~ "Mollusca", + TRUE ~ NA_character_)) |> + dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habitat", "Sensitivity") ~ paste0(Category, ": ", Type), + Category %in% c("Taxa Group") ~ paste0(Category, ": ", Type), + Category %in% c("Overall") ~ paste0(Category, " ", Metric), + Metric %in% c("Index") ~ paste0(Metric, ": ", Category), + Metric %in% c("Fraction") ~ paste0(Metric, ": ", Category), + TRUE ~ NA_character_)) + + return(bmi) +} From 622787b593bdd53899ba232d46f6a493e49e2720 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 09:34:11 -0700 Subject: [PATCH 16/27] Minor change to plot formatting --- R/wq-qc.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/wq-qc.R b/R/wq-qc.R index 2eccdb4..18b9099 100644 --- a/R/wq-qc.R +++ b/R/wq-qc.R @@ -378,6 +378,7 @@ WqPlotDepthProfile <- function(param, units, park, site, field.season, include.t # "Value: ", Median, "
", # "Measurement Depth (m): ", Depth_m, "
")) + ggplot2::labs(color = paste0("Median ", param, ifelse(tolower(param) == "ph", "", paste0(" (", units, ")")))) + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 60, hjust = 1)) + ggplot2::geom_point(size = 3, pch = 19, stroke = 2, color = "black") + ggplot2::geom_point(size = 3, pch = 19) # color = "#3b3b3b", pch = 21 From 31f1f6b8ff2d79ee104cde658924d0674529bf88 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 09:35:29 -0700 Subject: [PATCH 17/27] Updates to function names --- NAMESPACE | 12 +- R/levels-qc.R | 260 ++++++++++++++---- man/BMILong.Rd | 28 ++ man/BenchmarkConsistencyPlot.Rd | 27 ++ man/{ChemANC.Rd => ChemFormatted.Rd} | 10 +- man/ChemLakeIonSplitPlot.Rd | 21 ++ man/ChemLakeNutrientSplitPlot.Rd | 21 ++ man/ChemStreamIonSplitPlot.Rd | 21 ++ man/ChemStreamNutrientSplitPlot.Rd | 21 ++ man/GetRawData.Rd | 8 +- man/GetSiteName.Rd | 10 +- man/PlotStringComparisons.Rd | 23 ++ man/StringSurveyElevation.Rd | 27 ++ man/SurveyPointElevation.Rd | 4 +- ...Elevation.Rd => qcBenchmarkConsistency.Rd} | 10 +- man/qcStringSurveyElevations.Rd | 2 +- 16 files changed, 428 insertions(+), 77 deletions(-) create mode 100644 man/BMILong.Rd create mode 100644 man/BenchmarkConsistencyPlot.Rd rename man/{ChemANC.Rd => ChemFormatted.Rd} (80%) create mode 100644 man/ChemLakeIonSplitPlot.Rd create mode 100644 man/ChemLakeNutrientSplitPlot.Rd create mode 100644 man/ChemStreamIonSplitPlot.Rd create mode 100644 man/ChemStreamNutrientSplitPlot.Rd create mode 100644 man/PlotStringComparisons.Rd create mode 100644 man/StringSurveyElevation.Rd rename man/{qcBenchmarkElevation.Rd => qcBenchmarkConsistency.Rd} (75%) diff --git a/NAMESPACE b/NAMESPACE index b0284ba..a297f58 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,22 +4,28 @@ export(BMIDiversityMetricsPlot) export(BMIFormatted) export(BMIFunctionalMetricsPlot) export(BMIGeneralMetricsPlot) +export(BMILong) export(BMIMetricsLong) export(BMISensitivityMetricsPlot) export(BMISpecies) export(BMITaxonomicMetricsPlot) +export(BenchmarkConsistencyPlot) export(ChannelCharacteristics) export(ChannelFlow) export(ChannelSubstrate) -export(ChemANC) +export(ChemFormatted) export(ChemLakeANCPlot) export(ChemLakeIonPlot) +export(ChemLakeIonSplitPlot) export(ChemLakeNutrientBarPlot) export(ChemLakeNutrientPlot) +export(ChemLakeNutrientSplitPlot) export(ChemStreamANCPlot) export(ChemStreamIonPlot) +export(ChemStreamIonSplitPlot) export(ChemStreamNutrientBarPlot) export(ChemStreamNutrientPlot) +export(ChemStreamNutrientSplitPlot) export(CloseDatabaseConnection) export(FormatPlot) export(GetRawData) @@ -29,10 +35,12 @@ export(LakeWqMedian) export(LoadStreamsAndLakes) export(PlotBenchmarkElevation) export(PlotLakeSurfaceElevation) +export(PlotStringComparisons) export(ReadAndFilterData) export(ReadCSV) export(SaveDataToCsv) export(StreamWqMedian) +export(StringSurveyElevation) export(SurveyPointElevation) export(WqDailyMean) export(WqDailyMeanLong) @@ -44,7 +52,7 @@ export(expect_dataframe_equal) export(fetchAndWrangleAGOL) export(getMDLLookup) export(qcBMIDiscrepancies) -export(qcBenchmarkElevation) +export(qcBenchmarkConsistency) export(qcChemFieldBlanks) export(qcChemFieldDupes) export(qcChemFlags) diff --git a/R/levels-qc.R b/R/levels-qc.R index 07b5247..f6e14f3 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -1,4 +1,4 @@ -#' Calculates mean elevations for each survey point type in a survey +#' Calculates mean elevations for each survey point type in a survey (digital level) #' #' @inheritParams ReadAndFilterData #' @@ -63,7 +63,8 @@ SurveyPointElevation <- function(park, site, field.season) { # Calc elevations for current setup bs <- bs |> dplyr::select(-RM1_GivenElevation_m, -TempCorrectedHeight_ft, -SurveyPoint) - temp_lvls <- levels |> dplyr::filter(SetupNumber == setup) |> + temp_lvls <- levels |> + dplyr::filter(SetupNumber == setup) |> dplyr::left_join(bs, by = c("SiteCode", "VisitDate", "FieldSeason", "VisitType", "SetupNumber")) |> dplyr::mutate(TempCorrectedElevation_ft = InstrumentHeight_ft - TempCorrectedHeight_ft) temp_corrected_lvls <- rbind(temp_corrected_lvls, temp_lvls) @@ -98,11 +99,56 @@ SurveyPointElevation <- function(park, site, field.season) { unique() |> dplyr::filter(!grepl("TP", SurveyPoint)) |> dplyr::ungroup() |> - dplyr::filter(!(SiteShort == "DEAD0" & FieldSeason == "2021" & SurveyPoint == "WS")) + dplyr::filter(!(SiteShort == "DEAD0" & FieldSeason == "2021" & SurveyPoint == "WS")) |> + dplyr::filter(VisitType == "Primary") |> + dplyr::select(-c(VisitType, DPL, SurveyPoint)) |> + dplyr::rename(FinalElevation_ft = FinalCorrectedElevation_ft) |> + dplyr::relocate(ClosureError_ft, .after = "FinalElevation_ft") |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") return(final_lvls) } +#' Calculates mean elevations for each survey point type in a survey (string) +#' +#' @inheritParams ReadAndFilterData +#' +#' @return A tibble +#' @export +#' +#' @examples +#' \dontrun{ +#' StringSurveyElevation() +#' StringSurveyElevation(site = "GRBA_L_BAKR0", field.season = "2016") +#' } + +StringSurveyElevation <- function(park, site, field.season) { + str <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") + + elevs <- str |> + dplyr::filter(VisitType == "Primary") |> + dplyr::select(-c(VisitType, DPL, RM1_GivenElevation_m)) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, Benchmark) |> + dplyr::summarise(MeanHeight_ft = mean(Height_ft), + StDev_ft = sd(Height_ft), + Count = dplyr::n()) |> + dplyr::ungroup() |> + dplyr::mutate(Offset_ft = dplyr::case_when(grepl("BM1", Benchmark) ~ (measurements::conv_unit(100, "m", "ft") - MeanHeight_ft), + (SiteCode %in% c("GRBA_L_DEAD0") & grepl("BM4", Benchmark)) ~ (measurements::conv_unit(102.105, "m", "ft") - MeanHeight_ft), + TRUE ~ NA)) |> + dplyr::group_by(SiteCode, FieldSeason) |> + tidyr::fill(Offset_ft) |> + dplyr::ungroup() |> + dplyr::mutate(FinalElevation_ft = dplyr::case_when(grepl("BM1", Benchmark) ~ (measurements::conv_unit(100, "m", "ft")), + TRUE ~ MeanHeight_ft + Offset_ft)) |> + dplyr::select(-c(MeanHeight_ft, Offset_ft)) |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> + dplyr::relocate(FinalElevation_ft, .after = "Benchmark") + + return(elevs) + +} + #' Calculates lake level elevations #' #' @inheritParams ReadAndFilterData @@ -159,15 +205,16 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::filter(Benchmark == "Water Surface") |> dplyr::mutate(SurveyType = "Digital Level", BenchmarkUsed = NA_character_) |> - dplyr::rename(FinalElevation_ft = FinalCorrectedElevation_ft) |> - dplyr::select(-SurveyPoint, -Benchmark, -DPL) |> - dplyr::relocate(SurveyType, .after = "VisitType") |> - dplyr::relocate(FinalElevation_ft, .after = "SurveyType") + dplyr::select(-Benchmark) |> + dplyr::relocate(FinalElevation_ft, .after = "SurveyType") |> + dplyr::relocate(ClosureError_ft, .after = "FinalElevation_ft") } string <- string |> + dplyr::filter(VisitType == "Primary") |> + dplyr::select(-c(DPL, VisitType)) |> dplyr::mutate(BenchmarkNumber = substring(Benchmark, nchar(Benchmark))) |> - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason) |> dplyr::mutate(MinBenchmark = min(BenchmarkNumber), BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> dplyr::filter(BenchmarkNumber == MinBenchmark) |> @@ -176,7 +223,7 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::mutate(BenchmarkUsed = Benchmark, ClosureError_ft = as.double(NA), SurveyType = "String") |> - dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) |> + dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) |> unique() not_all_na <- function(x) any(!is.na(x)) @@ -186,7 +233,8 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::select(where(not_all_na)) |> dplyr::mutate(FinalElevation_m = measurements::conv_unit(FinalElevation_ft, "ft", "m"), ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) |> - dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") + dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") |> + dplyr::select(-c(ClosureError_ft, ClosureError_m, BenchmarkUsed)) return(lake_elevation) } @@ -201,33 +249,82 @@ LakeSurfaceElevation <- function(park, site, field.season) { #' #' @examples #' \dontrun{ -#' qcBenchmarkElevation() -#' qcBenchmarkElevation(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) +#' qcBenchmarkConsistency() +#' qcBenchmarkConsistency(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) #' } -qcBenchmarkElevation <- function(park, site, field.season, sd_cutoff = NA) { - lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) +qcBenchmarkConsistency <- function(park, site, field.season, sd_cutoff = NA) { + lvls.dl <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + dplyr::mutate(Method = "Digital Level") |> + dplyr::select(-c(ClosureError_ft)) + + lvls.str <- StringSurveyElevation(park = park, site = site, field.season = field.season) |> + dplyr::mutate(Method = "String") |> + dplyr::select(-c(StDev_ft, Count)) - lvls <- lvls |> - dplyr::select(Park, SiteShort, SiteCode, SiteName, Benchmark, FinalCorrectedElevation_ft) |> + lvls.all <- rbind(lvls.dl, lvls.str) |> dplyr::filter(Benchmark != "Water Surface") |> - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, Benchmark) |> - dplyr::summarize(MeanElevation_ft = mean(FinalCorrectedElevation_ft), - StDevElevation_ft = sd(FinalCorrectedElevation_ft), - Count = n()) |> - dplyr::ungroup() + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, Benchmark, Method) |> + dplyr::summarize(MeanElevation_ft = mean(FinalElevation_ft), + StDev_ft = sd(FinalElevation_ft), + Count = dplyr::n()) |> + dplyr::ungroup() |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") if (!is.na(sd_cutoff)) { lvls <- lvls |> - dplyr::filter(StDevElevation_ft >= sd_cutoff) + dplyr::filter(StDev_ft >= sd_cutoff) } - return(lvls) + return(lvls.all) +} + +#' Plot median, quartile, and outlier elevations for each benchmark that is not assigned a given elevation (e.g., Benchmark 1) +#' +#' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". +#' @param field.season Optional. Field season name to filter on, e.g. "2019". +#' +#' @return A ggplot object +#' @export +#' +#' @examples +#' \dontrun{ +#' BenchmarkConsistencyPlot() +#' BenchmarkConsistencyPlot(site = "GRBA_L_BAKR0") +#' } +BenchmarkConsistencyPlot <- function(park, site, field.season) { + lvls.dl <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + dplyr::mutate(Method = "Digital Level") |> + dplyr::select(-c(ClosureError_ft)) + + lvls.str <- StringSurveyElevation(park = park, site = site, field.season = field.season) |> + dplyr::mutate(Method = "String") |> + dplyr::select(-c(StDev_ft, Count)) + + lvls.all <- rbind(lvls.dl, lvls.str) |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> + dplyr::filter(!(Benchmark %in% c("Water Surface", "BM1", "BM4"))) + + plt <- ggplot2::ggplot(data = lvls.all, + ggplot2::aes(x = Benchmark, + y = FinalElevation_ft, + group = interaction(Benchmark, Method), + fill = Method)) + + ggplot2::geom_boxplot() + + ggplot2::facet_wrap(SiteName~., + ncol = 3, + scales = "free") + + khroma::scale_fill_bright() + + ggplot2::theme(legend.position="bottom") + + return(plt) + } #' Calculates mean and standard deviation of string survey heights for each benchmark #' -#' @inheritParams qcBenchmarkElevation +#' @inheritParams qcBenchmarkConsistency #' #' @return A tibble #' @export @@ -241,7 +338,8 @@ qcStringSurveyHeights <- function(park, site, field.season, sd_cutoff = NA) { str_survey <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) |> dplyr::summarise(MeanHeight_ft = mean(Height_ft), - StDevHeight_ft = sd(Height_ft)) |> + StDevHeight_ft = sd(Height_ft), + Count = dplyr::n()) |> dplyr::ungroup() if (!is.na(sd_cutoff)) { @@ -255,9 +353,9 @@ qcStringSurveyHeights <- function(park, site, field.season, sd_cutoff = NA) { #' Calculates mean and standard deviation of string survey lake level elevations for each year #' -#' @inheritParams qcBenchmarkElevation +#' @inheritParams qcBenchmarkConsistency #' -#' @return A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanFinalElevation_ft, StDevFinalElevation_ft +#' @return A tibble #' @export #' #' @examples @@ -383,32 +481,46 @@ qcClosureErrorDiscrepancies <- function(park, site, field.season) { #' PlotBenchmarkElevation(site = "GRBA_L_DEAD0", plotly = TRUE) #' } PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) { - lvls <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + str <- StringSurveyElevation(park = park, site = site, field.season = field.season) |> + dplyr::select(-c(StDev_ft, Count)) |> + dplyr::mutate(Method = "String") + + dl <- SurveyPointElevation(park = park, site = site, field.season = field.season) |> + dplyr::select(-c(ClosureError_ft)) |> dplyr::filter(Benchmark != "Water Surface") |> - tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") + dplyr::mutate(Method = "Digital Level") - ptol_muted_6 <- c("#CC6677", "#332288", "#DDCC77", "#117733", "#88CCEE", "#882255") + lvls <- rbind(str, dl) |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, Benchmark, Method)) - plt <- FormatPlot(lvls, - FieldSeason, - FinalCorrectedElevation_ft, - SiteName, - # plot.title = ifelse(include.title, "Benchmark elevation over time", ""), - x.lab = "Field Season", - y.lab = "Elevation (ft)") + - ggplot2::aes(color = Benchmark, - group = Benchmark, - text = paste0("Field Season: ", FieldSeason, "
", - "Survey Point: ", SurveyPoint, "
", - "Benchmark: ", Benchmark, "
", - "Elevation (ft): ", round(FinalCorrectedElevation_ft, 2))) + - ggplot2::geom_point(ggplot2::aes()) + - ggplot2::geom_line(linewidth = 1) + - khroma::scale_color_muted() + ptol_muted_6 <- c("#CC6677", "#332288", "#DDCC77", "#117733", "#88CCEE", "#882255") - if (plotly) { - plt <- plotly::ggplotly(plt, tooltip = "text") - } + plt <- ggplot2::ggplot(data = lvls, + ggplot2::aes(x = FieldSeason, + y = FinalElevation_ft, + color = Benchmark, + group = interaction(Benchmark, Method, SiteName), + text = paste0("Field Season: ", FieldSeason, "
", + "Benchmark: ", Benchmark, "
", + "Elevation (ft): ", round(FinalElevation_ft, 2), "
", + "Method: ", Method))) + + ggplot2::geom_point(size = 2.2, + ggplot2::aes(shape = Method)) + + ggplot2::geom_line(linewidth = 1, + ggplot2::aes(linetype = Method)) + + ggplot2::facet_wrap(SiteName~., + ncol = 2, + scales = "free_y") + + khroma::scale_color_muted() + + ggplot2::labs(title = "Benchmark elevation over time", + x = "Field Season", + y = "Elevation (ft)") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1)) + + if (plotly) { + plt <- plotly::ggplotly(plt, tooltip = "text") + } return(plt) } @@ -444,7 +556,7 @@ PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = T text = paste0("Field Season: ", FieldSeason, "
", "Survey Type: ", SurveyType, "
", "Elevation (ft): ", round(FinalElevation_ft, 2))) + - ggplot2::geom_point(ggplot2::aes()) + + ggplot2::geom_point(size = 2.2) + ggplot2::geom_line(linewidth = 1) + ggplot2::scale_shape_discrete(na.translate = FALSE) + khroma::scale_color_muted() @@ -455,3 +567,51 @@ PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = T return(plt) } + +#' Plot lake levels determined by all benchmarks where string method was used +#' +#' @param park +#' @param site +#' @param field.season +#' +#' @return A ggplot object +#' @export +#' +#' @examples +#' \dontrun{ +#' PlotStringComparisons() +#' PlotStringComparisons(site = "GRBA_L_DEAD0") +#' } +PlotStringComparisons <- function(park, site, field.season) { + str <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") + + mean <- str |> + dplyr::filter(VisitType == "Primary", + IsLakeDry == FALSE) |> + dplyr::select(-c(VisitType, DPL, IsLakeDry)) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, Benchmark, RM1_GivenElevation_m) |> + dplyr::summarize(MeanHeight_ft = mean(Height_ft)) |> + dplyr::ungroup() |> + dplyr::mutate(GivenElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft"), + LakeElevation_ft = GivenElevation_ft - MeanHeight_ft) |> + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> + tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName)) + + plt <- ggplot2::ggplot(mean, + ggplot2::aes(x = FieldSeason, + y = LakeElevation_ft, + group = Benchmark, + color = Benchmark)) + + ggplot2::geom_point(size = 2.5, + ggplot2::aes(shape = Benchmark)) + + ggplot2::facet_wrap(SiteName~., + ncol = 2, + scales = "free_y") + + khroma::scale_color_muted() + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1)) + + ggplot2::labs(title = "Lake surface elevations by benchmark", + x = "Field Season", + y = "Elevation (ft)") + + return(plt) +} diff --git a/man/BMILong.Rd b/man/BMILong.Rd new file mode 100644 index 0000000..ad696e2 --- /dev/null +++ b/man/BMILong.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bmi-qc.R +\name{BMILong} +\alias{BMILong} +\title{Pivot BMI data to long format (Deprecated data! Use for QC purposes only)} +\usage{ +BMILong(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A tibble +} +\description{ +Pivot BMI data to long format (Deprecated data! Use for QC purposes only) +} +\examples{ +\dontrun{ +BMILong() +BMILong(site = "GRBA_S_MILL1") +BMILong(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015") +} +} diff --git a/man/BenchmarkConsistencyPlot.Rd b/man/BenchmarkConsistencyPlot.Rd new file mode 100644 index 0000000..43801d3 --- /dev/null +++ b/man/BenchmarkConsistencyPlot.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{BenchmarkConsistencyPlot} +\alias{BenchmarkConsistencyPlot} +\title{Plot median, quartile, and outlier elevations for each benchmark that is not assigned a given elevation (e.g., Benchmark 1)} +\usage{ +BenchmarkConsistencyPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot median, quartile, and outlier elevations for each benchmark that is not assigned a given elevation (e.g., Benchmark 1) +} +\examples{ +\dontrun{ + BenchmarkConsistencyPlot() + BenchmarkConsistencyPlot(site = "GRBA_L_BAKR0") +} +} diff --git a/man/ChemANC.Rd b/man/ChemFormatted.Rd similarity index 80% rename from man/ChemANC.Rd rename to man/ChemFormatted.Rd index 6ce5890..0ed1ab5 100644 --- a/man/ChemANC.Rd +++ b/man/ChemFormatted.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/chem-qc.R -\name{ChemANC} -\alias{ChemANC} -\title{Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2)} +\name{ChemFormatted} +\alias{ChemFormatted} +\title{Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) and fill missing years with NAs for ease of plotting} \usage{ -ChemANC(park, site, field.season) +ChemFormatted(park, site, field.season) } \arguments{ \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} @@ -17,7 +17,7 @@ ChemANC(park, site, field.season) A tibble with columns Park, SiteShort, SiteCode, SiteName, FieldSeason, SampleFrame, VisitDate, VisitType, SampleCollectionMethod, Characteristic, CharacteristicLabel, LabValue, ReportingGroup, SampleType, Flag, FlagNote, DPL, Unit } \description{ -Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) +Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) and fill missing years with NAs for ease of plotting } \examples{ \dontrun{ diff --git a/man/ChemLakeIonSplitPlot.Rd b/man/ChemLakeIonSplitPlot.Rd new file mode 100644 index 0000000..f283f76 --- /dev/null +++ b/man/ChemLakeIonSplitPlot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chem-qc.R +\name{ChemLakeIonSplitPlot} +\alias{ChemLakeIonSplitPlot} +\title{Plot lake ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets.} +\usage{ +ChemLakeIonSplitPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot lake ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets. +} diff --git a/man/ChemLakeNutrientSplitPlot.Rd b/man/ChemLakeNutrientSplitPlot.Rd new file mode 100644 index 0000000..c27a70e --- /dev/null +++ b/man/ChemLakeNutrientSplitPlot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chem-qc.R +\name{ChemLakeNutrientSplitPlot} +\alias{ChemLakeNutrientSplitPlot} +\title{Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets.} +\usage{ +ChemLakeNutrientSplitPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot lake nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets. +} diff --git a/man/ChemStreamIonSplitPlot.Rd b/man/ChemStreamIonSplitPlot.Rd new file mode 100644 index 0000000..15a7a8a --- /dev/null +++ b/man/ChemStreamIonSplitPlot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chem-qc.R +\name{ChemStreamIonSplitPlot} +\alias{ChemStreamIonSplitPlot} +\title{Plot stream ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets.} +\usage{ +ChemStreamIonSplitPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot stream ion (ANC2, Na, Mg, K, Ca, SO4-S, Cl) concentration data for all parks and field seasons split into facets. +} diff --git a/man/ChemStreamNutrientSplitPlot.Rd b/man/ChemStreamNutrientSplitPlot.Rd new file mode 100644 index 0000000..72b4bc8 --- /dev/null +++ b/man/ChemStreamNutrientSplitPlot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/chem-qc.R +\name{ChemStreamNutrientSplitPlot} +\alias{ChemStreamNutrientSplitPlot} +\title{Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets.} +\usage{ +ChemStreamNutrientSplitPlot(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A ggplot object +} +\description{ +Plot stream nutrient (UTN, TDN, NO2No3-N, UTP, TDP, DOC) concentration data for all parks and field seasons split into facets. +} diff --git a/man/GetRawData.Rd b/man/GetRawData.Rd index 54a15c2..1a52bef 100644 --- a/man/GetRawData.Rd +++ b/man/GetRawData.Rd @@ -12,15 +12,9 @@ GetRawData(park, site, field.season) \item{site}{Optional. Spring code to filter on, e.g. "GRBA_L_BAKR0".} \item{field.season}{Optional. Field season name to filter on, e.g. "2019".} - -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - -\item{data.source}{Character string indicating whether to access data in the desert springs database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} } \value{ -A list of dataframes containing raw streams and lakes data. +A list of dataframes containing raw streams and lakes data } \description{ Raw data dump diff --git a/man/GetSiteName.Rd b/man/GetSiteName.Rd index 690c6dd..f22237e 100644 --- a/man/GetSiteName.Rd +++ b/man/GetSiteName.Rd @@ -4,16 +4,16 @@ \alias{GetSiteName} \title{Get the name of a site from the site code} \usage{ -GetSiteName(conn, path.to.data, site.code, data.source = "database") +GetSiteName(site.code, data.source = "database") } \arguments{ -\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} - -\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} - \item{site.code}{Spring code to get the name for, e.g. "GRBA_L_BAKR0".} \item{data.source}{Character string indicating whether to access data in the Streams and Lakes database (\code{"database"}, default) or to use data saved locally (\code{"local"}). In order to access the most up-to-date data, it is recommended that you select \code{"database"} unless you are working offline or your code will be shared with someone who doesn't have access to the database.} + +\item{conn}{Database connection generated from call to \code{OpenDatabaseConnection()}. Ignored if \code{data.source} is \code{"local"}.} + +\item{path.to.data}{The directory containing the csv data exports generated from \code{SaveDataToCsv()}. Ignored if \code{data.source} is \code{"database"}.} } \value{ The name of the site diff --git a/man/PlotStringComparisons.Rd b/man/PlotStringComparisons.Rd new file mode 100644 index 0000000..f6ee228 --- /dev/null +++ b/man/PlotStringComparisons.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{PlotStringComparisons} +\alias{PlotStringComparisons} +\title{Plot lake levels determined by all benchmarks where string method was used} +\usage{ +PlotStringComparisons(park, site, field.season) +} +\arguments{ +\item{field.season}{} +} +\value{ +A ggplot object +} +\description{ +Plot lake levels determined by all benchmarks where string method was used +} +\examples{ +\dontrun{ +PlotStringComparisons() +PlotStringComparisons(site = "GRBA_L_DEAD0") +} +} diff --git a/man/StringSurveyElevation.Rd b/man/StringSurveyElevation.Rd new file mode 100644 index 0000000..038c0cd --- /dev/null +++ b/man/StringSurveyElevation.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/levels-qc.R +\name{StringSurveyElevation} +\alias{StringSurveyElevation} +\title{Calculates mean elevations for each survey point type in a survey (string)} +\usage{ +StringSurveyElevation(park, site, field.season) +} +\arguments{ +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR0".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} +} +\value{ +A tibble +} +\description{ +Calculates mean elevations for each survey point type in a survey (string) +} +\examples{ +\dontrun{ + StringSurveyElevation() + StringSurveyElevation(site = "GRBA_L_BAKR0", field.season = "2016") +} +} diff --git a/man/SurveyPointElevation.Rd b/man/SurveyPointElevation.Rd index a415553..5635505 100644 --- a/man/SurveyPointElevation.Rd +++ b/man/SurveyPointElevation.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/levels-qc.R \name{SurveyPointElevation} \alias{SurveyPointElevation} -\title{Calculates mean elevations for each survey point type in a survey} +\title{Calculates mean elevations for each survey point type in a survey (digital level)} \usage{ SurveyPointElevation(park, site, field.season) } @@ -17,7 +17,7 @@ SurveyPointElevation(park, site, field.season) A tibble } \description{ -Calculates mean elevations for each survey point type in a survey +Calculates mean elevations for each survey point type in a survey (digital level) } \examples{ \dontrun{ diff --git a/man/qcBenchmarkElevation.Rd b/man/qcBenchmarkConsistency.Rd similarity index 75% rename from man/qcBenchmarkElevation.Rd rename to man/qcBenchmarkConsistency.Rd index 36a6622..5622b18 100644 --- a/man/qcBenchmarkElevation.Rd +++ b/man/qcBenchmarkConsistency.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/levels-qc.R -\name{qcBenchmarkElevation} -\alias{qcBenchmarkElevation} +\name{qcBenchmarkConsistency} +\alias{qcBenchmarkConsistency} \title{Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons} \usage{ -qcBenchmarkElevation(park, site, field.season, sd_cutoff = NA) +qcBenchmarkConsistency(park, site, field.season, sd_cutoff = NA) } \arguments{ \item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} @@ -23,7 +23,7 @@ Calculates mean and standard deviation of final corrected elevations for each be } \examples{ \dontrun{ - qcBenchmarkElevation() - qcBenchmarkElevation(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) + qcBenchmarkConsistency() + qcBenchmarkConsistency(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019")) } } diff --git a/man/qcStringSurveyElevations.Rd b/man/qcStringSurveyElevations.Rd index d35ba22..268be09 100644 --- a/man/qcStringSurveyElevations.Rd +++ b/man/qcStringSurveyElevations.Rd @@ -16,7 +16,7 @@ qcStringSurveyElevations(park, site, field.season, sd_cutoff = NA) \item{sd_cutoff}{Optional. If specified, only return benchmarks where standard deviation of final corrected elevations is greater than or equal to \code{sd_cutoff}.} } \value{ -A tibble with columns Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, MeanFinalElevation_ft, StDevFinalElevation_ft +A tibble } \description{ Calculates mean and standard deviation of string survey lake level elevations for each year From 594c608c727bf3a294d3bc970dcd9fdd2acde080 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 10:57:37 -0700 Subject: [PATCH 18/27] Modified lake levels function to integrate string method authoritative benchmarks --- R/levels-qc.R | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/R/levels-qc.R b/R/levels-qc.R index f6e14f3..61c4032 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -121,29 +121,28 @@ SurveyPointElevation <- function(park, site, field.season) { #' StringSurveyElevation() #' StringSurveyElevation(site = "GRBA_L_BAKR0", field.season = "2016") #' } - StringSurveyElevation <- function(park, site, field.season) { str <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") elevs <- str |> dplyr::filter(VisitType == "Primary") |> + dplyr::mutate(GivenElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> dplyr::select(-c(VisitType, DPL, RM1_GivenElevation_m)) |> - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, Benchmark) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, AuthoritativeBenchmark, Benchmark, GivenElevation_ft) |> dplyr::summarise(MeanHeight_ft = mean(Height_ft), StDev_ft = sd(Height_ft), Count = dplyr::n()) |> dplyr::ungroup() |> - dplyr::mutate(Offset_ft = dplyr::case_when(grepl("BM1", Benchmark) ~ (measurements::conv_unit(100, "m", "ft") - MeanHeight_ft), - (SiteCode %in% c("GRBA_L_DEAD0") & grepl("BM4", Benchmark)) ~ (measurements::conv_unit(102.105, "m", "ft") - MeanHeight_ft), + dplyr::mutate(Offset_ft = dplyr::case_when(AuthoritativeBenchmark == Benchmark ~ GivenElevation_ft - MeanHeight_ft, TRUE ~ NA)) |> dplyr::group_by(SiteCode, FieldSeason) |> tidyr::fill(Offset_ft) |> dplyr::ungroup() |> - dplyr::mutate(FinalElevation_ft = dplyr::case_when(grepl("BM1", Benchmark) ~ (measurements::conv_unit(100, "m", "ft")), + dplyr::mutate(Elevation_ft = dplyr::case_when(AuthoritativeBenchmark == Benchmark ~ GivenElevation_ft, TRUE ~ MeanHeight_ft + Offset_ft)) |> - dplyr::select(-c(MeanHeight_ft, Offset_ft)) |> + dplyr::select(-c(MeanHeight_ft, Offset_ft, AuthoritativeBenchmark, GivenElevation_ft)) |> tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> - dplyr::relocate(FinalElevation_ft, .after = "Benchmark") + dplyr::relocate(Elevation_ft, .after = "Benchmark") return(elevs) @@ -181,7 +180,7 @@ LakeSurfaceElevation <- function(park, site, field.season) { Height_ft = double() ) } else { - string <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") + import <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelString") } t2 <- try(SurveyPointElevation(park = park, site = site, field.season = field.season)) @@ -206,32 +205,31 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::mutate(SurveyType = "Digital Level", BenchmarkUsed = NA_character_) |> dplyr::select(-Benchmark) |> - dplyr::relocate(FinalElevation_ft, .after = "SurveyType") |> - dplyr::relocate(ClosureError_ft, .after = "FinalElevation_ft") + dplyr::rename(Elevation_ft = FinalElevation_ft) |> + dplyr::relocate(Elevation_ft, .after = "SurveyType") |> + dplyr::relocate(ClosureError_ft, .after = "Elevation_ft") } - string <- string |> - dplyr::filter(VisitType == "Primary") |> - dplyr::select(-c(DPL, VisitType)) |> - dplyr::mutate(BenchmarkNumber = substring(Benchmark, nchar(Benchmark))) |> - dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason) |> - dplyr::mutate(MinBenchmark = min(BenchmarkNumber), - BenchmarkElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> - dplyr::filter(BenchmarkNumber == MinBenchmark) |> - dplyr::mutate(FinalElevation_ft = mean(BenchmarkElevation_ft - Height_ft)) |> + string <- import |> + dplyr::filter(VisitType == "Primary", IsLakeDry == FALSE, Benchmark == AuthoritativeBenchmark) |> + dplyr::mutate(GivenElevation_ft = measurements::conv_unit(RM1_GivenElevation_m, "m", "ft")) |> + dplyr::select(-c(DPL, VisitType, RM1_GivenElevation_m, IsLakeDry, AuthoritativeBenchmark)) |> + dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, Benchmark, GivenElevation_ft) |> + dplyr::summarize(MeanHeight_ft = mean(Height_ft)) |> dplyr::ungroup() |> - dplyr::mutate(BenchmarkUsed = Benchmark, + tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |> + dplyr::mutate(Elevation_ft = GivenElevation_ft - MeanHeight_ft, + BenchmarkUsed = Benchmark, ClosureError_ft = as.double(NA), SurveyType = "String") |> - dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) |> - unique() + dplyr::select(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, SurveyType, Elevation_ft, ClosureError_ft, BenchmarkUsed) not_all_na <- function(x) any(!is.na(x)) lake_elevation <- rbind(string, survey) |> dplyr::filter((FieldSeason == "2018" & SurveyType == "Digital Level") | FieldSeason != "2018") |> dplyr::select(where(not_all_na)) |> - dplyr::mutate(FinalElevation_m = measurements::conv_unit(FinalElevation_ft, "ft", "m"), + dplyr::mutate(Elevation_m = measurements::conv_unit(Elevation_ft, "ft", "m"), ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) |> dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") |> dplyr::select(-c(ClosureError_ft, ClosureError_m, BenchmarkUsed)) @@ -547,7 +545,7 @@ PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = T plt <- FormatPlot(data = elev, x.col = FieldSeason, - y.col = FinalElevation_ft, + y.col = Elevation_ft, plot.title = ifelse(include.title, "Lake surface elevation over time", ""), x.lab = "Field Season", y.lab = "Elevation (ft)") + @@ -555,7 +553,7 @@ PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = T group = SiteName, text = paste0("Field Season: ", FieldSeason, "
", "Survey Type: ", SurveyType, "
", - "Elevation (ft): ", round(FinalElevation_ft, 2))) + + "Elevation (ft): ", round(Elevation_ft, 2))) + ggplot2::geom_point(size = 2.2) + ggplot2::geom_line(linewidth = 1) + ggplot2::scale_shape_discrete(na.translate = FALSE) + @@ -570,9 +568,9 @@ PlotLakeSurfaceElevation <- function(park, site, field.season, include.title = T #' Plot lake levels determined by all benchmarks where string method was used #' -#' @param park -#' @param site -#' @param field.season +#' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR1". +#' @param field.season Optional. Field season name to filter on, e.g. "2019". #' #' @return A ggplot object #' @export From 449a5b303c2689b8836ebcdf04fc1d083b7fb061 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 10:58:01 -0700 Subject: [PATCH 19/27] Minor updates to Roxygen --- R/utils.R | 7 +++++-- man/PlotStringComparisons.Rd | 6 +++++- man/ReadCSV.Rd | 12 ++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/R/utils.R b/R/utils.R index ee789c3..506a17a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -990,14 +990,17 @@ ReadSqlDatabase <- function(...) { return(data) } -#' Title +#' Read data from one or more CSVs #' #' @param data_path #' -#' @return +#' @return A list of data frames #' @export #' #' @examples +#' \dontrun{ +#' ReadCSV("path/to/csv/folder") +#' } ReadCSV <- function(data_path) { data_path <- normalizePath(data_path) col.spec <- GetColSpec() diff --git a/man/PlotStringComparisons.Rd b/man/PlotStringComparisons.Rd index f6ee228..2f51963 100644 --- a/man/PlotStringComparisons.Rd +++ b/man/PlotStringComparisons.Rd @@ -7,7 +7,11 @@ PlotStringComparisons(park, site, field.season) } \arguments{ -\item{field.season}{} +\item{park}{Optional. Four-letter park code to filter on, e.g. "GRBA".} + +\item{site}{Optional. Site code to filter on, e.g. "GRBA_L_BAKR1".} + +\item{field.season}{Optional. Field season name to filter on, e.g. "2019".} } \value{ A ggplot object diff --git a/man/ReadCSV.Rd b/man/ReadCSV.Rd index 4f7c7bb..1ba7b61 100644 --- a/man/ReadCSV.Rd +++ b/man/ReadCSV.Rd @@ -2,13 +2,21 @@ % Please edit documentation in R/utils.R \name{ReadCSV} \alias{ReadCSV} -\title{Title} +\title{Read data from one or more CSVs} \usage{ ReadCSV(data_path) } \arguments{ \item{data_path}{} } +\value{ +A list of data frames +} \description{ -Title +Read data from one or more CSVs +} +\examples{ +\dontrun{ +ReadCSV("path/to/csv/folder") +} } From 615548bd710c3c36900d512b99506d2b5720e89e Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 10:58:31 -0700 Subject: [PATCH 20/27] Added file to ignore --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..b420a7d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +test-space.R From 8925f0dfe09bebbe316d1d7631d71d0dfff232cb Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 11:32:17 -0700 Subject: [PATCH 21/27] Fixed minor typos --- R/levels-qc.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/levels-qc.R b/R/levels-qc.R index 61c4032..9eaf1e8 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -102,8 +102,8 @@ SurveyPointElevation <- function(park, site, field.season) { dplyr::filter(!(SiteShort == "DEAD0" & FieldSeason == "2021" & SurveyPoint == "WS")) |> dplyr::filter(VisitType == "Primary") |> dplyr::select(-c(VisitType, DPL, SurveyPoint)) |> - dplyr::rename(FinalElevation_ft = FinalCorrectedElevation_ft) |> - dplyr::relocate(ClosureError_ft, .after = "FinalElevation_ft") |> + dplyr::rename(Elevation_ft = FinalCorrectedElevation_ft) |> + dplyr::relocate(ClosureError_ft, .after = "Elevation_ft") |> tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") return(final_lvls) @@ -205,7 +205,6 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::mutate(SurveyType = "Digital Level", BenchmarkUsed = NA_character_) |> dplyr::select(-Benchmark) |> - dplyr::rename(Elevation_ft = FinalElevation_ft) |> dplyr::relocate(Elevation_ft, .after = "SurveyType") |> dplyr::relocate(ClosureError_ft, .after = "Elevation_ft") } From b78c3ad70c309b9be16bfeca92cc89ade2218d56 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 11:32:29 -0700 Subject: [PATCH 22/27] Added habit metrics plot function --- R/bmi-qc.R | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/R/bmi-qc.R b/R/bmi-qc.R index 1015d8d..15dfd4a 100644 --- a/R/bmi-qc.R +++ b/R/bmi-qc.R @@ -223,7 +223,7 @@ BMIFormatted <- function(park, site, field.season) { dplyr::mutate(Category = dplyr::case_when(Attribute %in% c("UniqueRichness") ~ "Overall", Attribute %in% c("Density") ~ "Overall", grepl("Feed", Attribute) ~ "Functional Feeding Group", - grepl("Habit", Attribute) ~ "Habitat", + grepl("Habit", Attribute) ~ "Habit", grepl("LongLived|Intolerant|Tolerant", Attribute) ~ "Sensitivity", grepl("Insecta|Ephemeroptera|Plecoptera|Trichoptera|Coleoptera|Elmidae|Diptera|Chironomidae|Megaloptera|Crustacea|NonInsects|Oligochaeta|Mollusca", Attribute) ~ "Taxa Group", grepl("DominantFamily", Attribute) ~ "Dominant Family", @@ -265,7 +265,7 @@ BMIFormatted <- function(park, site, field.season) { grepl("Oligochaeta", Attribute) ~ "Oligochaeta", grepl("Mollusca", Attribute) ~ "Mollusca", TRUE ~ NA_character_)) |> - dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habitat", "Sensitivity") ~ paste0(Category, ": ", Type), + dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habit", "Sensitivity") ~ paste0(Category, ": ", Type), Category %in% c("Taxa Group") ~ paste0(Category, ": ", Type), Category %in% c("Overall") ~ paste0(Category, " ", Metric), Metric %in% c("Index") ~ paste0(Metric, ": ", Category), @@ -439,6 +439,47 @@ BMIFunctionalMetricsPlot <- function(park, site, field.season) { } +#' Plot habit-related richness and abundance metrics for each BMI sample. +#' +#' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". +#' @param site Optional. Site code to filter on, e.g. "GRBA_L_BAKR0". +#' @param field.season Optional. Field season name to filter on, e.g. "2019". +#' +#' @return A ggplot object +#' @export +#' +BMIHabitMetricsPlot <- function(park, site, field.season) { + bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season) + + bmi.hab <- bmi.formatted |> + dplyr::filter(AnalysisType == "Routine", VisitType == "Primary", SiteShort != "BAKR2", + Category %in% c("Habit")) + + bmi.hab$Metric_f = factor(bmi.hab$Metric, levels = c("Richness", "Density")) + bmi.hab$Type_f = factor(bmi.hab$Type, levels = c("Burrower", "Climber", "Clinger", "Crawler", "Planktonic", "Skater", "Sprawler", "Swimmer")) + + bmi.hab.plot <- ggplot2::ggplot(bmi.hab, ggplot2::aes(x = FieldSeason, + y = Value, + color = Type_f, + text = paste0("Field Season: ", FieldSeason, "
", + "Count: ", Value, "
", + "Habit: ", Type_f))) + + ggplot2::geom_point() + + ggplot2::geom_line(ggplot2::aes(group = Type), + linewidth = 1) + + ggplot2::facet_grid(Metric_f~SiteShort, scales = "free_y") + + ggplot2::ylab(label = "Count") + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90), legend.position = "bottom") + + ggplot2::labs(title = "BMI habit metrics", color = "Habit") + + ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(), limits = c(0, NA)) + + ggplot2::scale_x_discrete(breaks = scales::pretty_breaks()) + + khroma::scale_color_muted() + + return(bmi.hab.plot) + +} + + #' Plot taxonomic-related richness and abundance metrics for each BMI sample. #' #' @param park Optional. Four-letter park code to filter on, e.g. "GRBA". @@ -527,7 +568,7 @@ BMILong <- function(park, site, field.season) { dplyr::mutate(Category = dplyr::case_when(Attribute %in% c("TotalCount") ~ "Overall", Attribute %in% c("TotalAbundance") ~ "Overall", grepl("Shredder|Scraper|Collector|Predator", Attribute) ~ "Functional Feeding Group", - grepl("Clinger", Attribute) ~ "Habitat", + grepl("Clinger", Attribute) ~ "Habit", grepl("LongLived|Intolerant|Tolerant", Attribute) ~ "Sensitivity", grepl("Insect|Ephemeroptera|Plecoptera|Trichoptera|Coleoptera|Elmidae|Diptera|Chironomidae|Megaloptera|Crustacea|NonInsect|Oligochaete|Mollusca", Attribute) ~ "Taxa Group", grepl("DominantFamily", Attribute) ~ "Dominant Family", @@ -570,7 +611,7 @@ BMILong <- function(park, site, field.season) { grepl("Oligochaete", Attribute) ~ "Oligochaeta", grepl("Mollusca", Attribute) ~ "Mollusca", TRUE ~ NA_character_)) |> - dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habitat", "Sensitivity") ~ paste0(Category, ": ", Type), + dplyr::mutate(Label = dplyr::case_when(Category %in% c("Functional Feeding Group", "Habit", "Sensitivity") ~ paste0(Category, ": ", Type), Category %in% c("Taxa Group") ~ paste0(Category, ": ", Type), Category %in% c("Overall") ~ paste0(Category, " ", Metric), Metric %in% c("Index") ~ paste0(Metric, ": ", Category), From 447b71bd988b482d8510bda89ea197b8c5c77bf1 Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 11:38:56 -0700 Subject: [PATCH 23/27] New function --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index a297f58..3a362f2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(BMIDiversityMetricsPlot) export(BMIFormatted) export(BMIFunctionalMetricsPlot) export(BMIGeneralMetricsPlot) +export(BMIHabitMetricsPlot) export(BMILong) export(BMIMetricsLong) export(BMISensitivityMetricsPlot) From a3dda91396c6d3cad5af27880a1fafbf5759901d Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 10 May 2024 14:06:11 -0700 Subject: [PATCH 24/27] Fixed minor errors --- R/levels-qc.R | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/R/levels-qc.R b/R/levels-qc.R index 9eaf1e8..dfdd694 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -195,7 +195,7 @@ LakeSurfaceElevation <- function(park, site, field.season) { FieldSeason = character(), VisitType = character(), SurveyType = character(), - FinalElevation_ft = double(), + Elevation_ft = double(), ClosureError_ft = double(), BenchmarkUsed = logical() ) @@ -261,8 +261,8 @@ qcBenchmarkConsistency <- function(park, site, field.season, sd_cutoff = NA) { lvls.all <- rbind(lvls.dl, lvls.str) |> dplyr::filter(Benchmark != "Water Surface") |> dplyr::group_by(Park, SiteShort, SiteCode, SiteName, Benchmark, Method) |> - dplyr::summarize(MeanElevation_ft = mean(FinalElevation_ft), - StDev_ft = sd(FinalElevation_ft), + dplyr::summarize(MeanElevation_ft = mean(Elevation_ft), + StDev_ft = sd(Elevation_ft), Count = dplyr::n()) |> dplyr::ungroup() |> tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") @@ -304,7 +304,7 @@ BenchmarkConsistencyPlot <- function(park, site, field.season) { plt <- ggplot2::ggplot(data = lvls.all, ggplot2::aes(x = Benchmark, - y = FinalElevation_ft, + y = Elevation_ft, group = interaction(Benchmark, Method), fill = Method)) + ggplot2::geom_boxplot() + @@ -398,8 +398,8 @@ qcElevationDiscrepancies <- function(park, site, field.season) { survey_elevs <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "LakeLevelSurvey") r_elevs_data <- r_elevs |> - dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, SurveyPoint, Benchmark, FinalCorrectedElevation_ft) |> - dplyr::rename(R_Elev_ft = FinalCorrectedElevation_ft) + dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, Benchmark, Elevation_ft) |> + dplyr::rename(R_Elev_ft = Elevation_ft) survey_elevs_data <- survey_elevs |> dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedWaterSurfaceElevation_m, FieldCalculatedRM2Elevation_m, FieldCalculatedRM3Elevation_m) |> @@ -416,7 +416,7 @@ qcElevationDiscrepancies <- function(park, site, field.season) { dplyr::select(-c("Survey_Elev_m")) elevs_data_joined <- r_elevs_data |> - dplyr::inner_join(survey_elevs_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason", "SurveyPoint")) |> + dplyr::inner_join(survey_elevs_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) |> dplyr::mutate(Elev_diff = round(as.numeric(format(R_Elev_ft - Survey_Elev_ft, scientific = FALSE)), 5)) |> dplyr::arrange(desc(abs(Elev_diff))) @@ -452,10 +452,8 @@ qcClosureErrorDiscrepancies <- function(park, site, field.season) { dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, FieldCalculatedClosureError) |> dplyr::rename(Survey_CE_ft = FieldCalculatedClosureError) |> unique() |> - dplyr::mutate(Survey_CE_ft = round(as.numeric(format(Survey_CE_ft, scientific = FALSE)), 4)) |> dplyr::filter(!is.na(Survey_CE_ft)) - ce_data_joined <- r_ce_data |> dplyr::inner_join(survey_ce_data, by = c("SiteCode", "SiteName", "VisitDate", "FieldSeason")) |> dplyr::mutate(CE_diff = round(as.numeric(format(R_CE_ft - Survey_CE_ft, scientific = FALSE)), 5)) |> @@ -495,12 +493,12 @@ PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRU plt <- ggplot2::ggplot(data = lvls, ggplot2::aes(x = FieldSeason, - y = FinalElevation_ft, + y = Elevation_ft, color = Benchmark, group = interaction(Benchmark, Method, SiteName), text = paste0("Field Season: ", FieldSeason, "
", "Benchmark: ", Benchmark, "
", - "Elevation (ft): ", round(FinalElevation_ft, 2), "
", + "Elevation (ft): ", round(Elevation_ft, 2), "
", "Method: ", Method))) + ggplot2::geom_point(size = 2.2, ggplot2::aes(shape = Method)) + From 68e24f56a3b91e0a73ec504432d884a324070f9d Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 17 May 2024 15:16:19 -0700 Subject: [PATCH 25/27] Minor updates to BMI metrics function based on updates to AGOL database --- R/bmi-qc.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/bmi-qc.R b/R/bmi-qc.R index 15dfd4a..ebced4b 100644 --- a/R/bmi-qc.R +++ b/R/bmi-qc.R @@ -15,14 +15,14 @@ BMIMetricsLong <- function(park, site, field.season) { metrics <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIMetrics") visit <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "BMIVisit") - meta <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") # Delete once VisitType is added to BMIVisit table + meta <- ReadAndFilterData(park = park, site = site, field.season = field.season, data.name = "Visit") - meta <- meta |> # Delete once VisitType is added to BMIVisit table - dplyr::select(SiteCode, VisitDate, SiteShort, VisitType) |> + meta <- meta |> + dplyr::select(SiteCode, SiteShort) |> unique() - visit <- visit |> # Add VisitType to selected columns once added to BMIVisit table in AGOL - dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) |> + visit <- visit |> + dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, VisitType, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount) |> dplyr::rename(VisitDate = CollectionDate) |> unique() @@ -32,7 +32,7 @@ BMIMetricsLong <- function(park, site, field.season) { join <- metrics |> dplyr::left_join(visit, by = "SampleID", relationship = "many-to-one") |> - dplyr::left_join(meta, by = c("SiteCode", "VisitDate"), relationship = "many-to-one") |> + dplyr::left_join(meta, by = "SiteCode", relationship = "many-to-one") |> dplyr::select(Laboratory, SampleID, Project, Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, AnalysisType, SamplerType, Area, FieldSplit, LabSplit, SplitCount, Attribute, Value) |> unique() From 57172c8e7dd5b786c4a239b53f532c4197d90720 Mon Sep 17 00:00:00 2001 From: Bailard Date: Thu, 30 May 2024 14:14:51 -0700 Subject: [PATCH 26/27] Added back deleted columns in LakeSurfaceElevation function for calculated data package CSV. --- R/levels-qc.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/levels-qc.R b/R/levels-qc.R index dfdd694..8663f80 100644 --- a/R/levels-qc.R +++ b/R/levels-qc.R @@ -230,8 +230,8 @@ LakeSurfaceElevation <- function(park, site, field.season) { dplyr::select(where(not_all_na)) |> dplyr::mutate(Elevation_m = measurements::conv_unit(Elevation_ft, "ft", "m"), ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) |> - dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") |> - dplyr::select(-c(ClosureError_ft, ClosureError_m, BenchmarkUsed)) + dplyr::relocate(any_of("BenchmarkUsed"), .after = "ClosureError_m") +# dplyr::select(-c(ClosureError_ft, ClosureError_m, BenchmarkUsed)) return(lake_elevation) } From f3ef1ff1c55c586a753af258c84e0b93dba8465d Mon Sep 17 00:00:00 2001 From: Bailard Date: Fri, 14 Jun 2024 14:09:24 -0700 Subject: [PATCH 27/27] Updated end year from MDL and ML lookup --- R/chem-qc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/chem-qc.R b/R/chem-qc.R index 0a18eb7..6a45a09 100644 --- a/R/chem-qc.R +++ b/R/chem-qc.R @@ -275,7 +275,7 @@ getMDLLookup <- function() { lookup <- tibble::tibble(Characteristic = c("ALK2", "Ca", "DOC", "Cl", "Mg", "NO3NO2-N", "UTN", "UTP", "K", "Na", "SO4-S"), Unit = c("mg CaCO3/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L", "mg/L"), StartYear = c(2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009), - EndYear = c(2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022), + EndYear = c(2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024), MDL = c(0.2, 0.06, 0.05, 0.01, 0.02, 0.001, 0.01, 0.002, 0.03, 0.01, 0.01), ML = c(0.6, 0.19, 0.16, 0.03, 0.06, 0.003, 0.03, 0.006, 0.10, 0.03, 0.03))