diff --git a/.Rbuildignore b/.Rbuildignore
index 91114bf..b420a7d 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
+test-space.R
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..3a362f2 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -4,32 +4,44 @@ export(BMIDiversityMetricsPlot)
export(BMIFormatted)
export(BMIFunctionalMetricsPlot)
export(BMIGeneralMetricsPlot)
+export(BMIHabitMetricsPlot)
export(BMILong)
+export(BMIMetricsLong)
+export(BMISensitivityMetricsPlot)
+export(BMISpecies)
export(BMITaxonomicMetricsPlot)
-export(BMIToleranceMetricsPlot)
+export(BenchmarkConsistencyPlot)
export(ChannelCharacteristics)
-export(ChannelFLow)
+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)
export(GetSiteName)
export(LakeSurfaceElevation)
export(LakeWqMedian)
-export(OpenDatabaseConnection)
+export(LoadStreamsAndLakes)
export(PlotBenchmarkElevation)
export(PlotLakeSurfaceElevation)
+export(PlotStringComparisons)
+export(ReadAndFilterData)
+export(ReadCSV)
export(SaveDataToCsv)
export(StreamWqMedian)
+export(StringSurveyElevation)
export(SurveyPointElevation)
export(WqDailyMean)
export(WqDailyMeanLong)
@@ -38,9 +50,10 @@ export(WqPlotPHDepthProfile)
export(WqPlotSpCondDepthProfile)
export(WqPlotTemperatureDepthProfile)
export(expect_dataframe_equal)
+export(fetchAndWrangleAGOL)
export(getMDLLookup)
export(qcBMIDiscrepancies)
-export(qcBenchmarkElevation)
+export(qcBenchmarkConsistency)
export(qcChemFieldBlanks)
export(qcChemFieldDupes)
export(qcChemFlags)
@@ -72,6 +85,7 @@ export(qcWqCompletenessPlot)
export(qcWqGrades)
export(qcWqGradesLong)
export(qcWqGradesPlot)
+export(writeBMI)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(stats,median)
diff --git a/R/bmi-qc.R b/R/bmi-qc.R
index 461c69f..ebced4b 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, SiteShort) |>
+ unique()
+
+ visit <- visit |>
+ dplyr::select(SampleID, Laboratory, Project, Park, SiteCode, SiteName, CollectionDate, FieldSeason, VisitType, 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 = "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()
+
+ 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(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")
- # 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(conn, path.to.data, park, site, field.season, data.source = "database") {
- bmi_issues <- BMILong(conn, path.to.data, park, site, field.season, data.source) %>%
- dplyr::select(Park, SiteShort, SiteCode, SiteName, FieldSeason, VisitDate, VisitType, SampleType, SampleCollectionMethod, BMIMethod, LabSampleNumber, TaxaGroup, TaxaGroupRichness, TaxaGroupDensity, LabNotes) %>%
+qcBMIDiscrepancies <- function(park, site, field.season) {
+ 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(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) {
+ 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")
+
+ visit <- visit |>
+ dplyr::select(SiteCode, VisitDate, VisitType)
- 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)) %>%
+ 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(conn, path.to.data, 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(conn, path.to.data, park, site, field.season, data.source = "database") {
- channel_flow <- ChannelCharacteristics(conn, path.to.data, park, site, field.season, data.source) %>%
- 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,94 +175,134 @@ ChannelFLow <- function(conn, path.to.data, park, site, field.season, data.sour
#' 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(conn, path.to.data, park, site, field.season, data.source = "database") {
- channel_substrate <- ChannelCharacteristics(conn, path.to.data, park, site, field.season, data.source) %>%
- 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) %>%
+ChannelSubstrate <- function(park, site, field.season) {
+ 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(conn, path.to.data, park, site, field.season, data.source = "database") {
- bmi_long <- BMILong(conn, path.to.data, park, site, field.season, data.source)
-
- 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)
+BMIFormatted <- function(park, site, field.season) {
+ 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) ~ "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",
+ 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", "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),
+ 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
#'
-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",
- 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,38 +321,31 @@ BMIGeneralMetricsPlot <- function(conn, path.to.data, 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
#'
-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)
-
- 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")
+BMIDiversityMetricsPlot <- function(park, site, field.season) {
+ bmi.formatted <- BMIFormatted(park = park, site = site, field.season = field.season)
- 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(conn, path.to.data, 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(conn, path.to.data, park, site, field.season, data.source = "database") {
- bmi.formatted <- BMIFormatted(conn, path.to.data, park, site, field.season, data.source)
+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,34 +400,31 @@ BMIToleranceMetricsPlot <- function(conn, path.to.data, 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
#'
-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",
- 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") +
@@ -415,40 +439,74 @@ BMIFunctionalMetricsPlot <- function(conn, path.to.data, park, site, field.seaso
}
+#' 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 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
#'
-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",
- 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") +
@@ -463,55 +521,102 @@ BMITaxonomicMetricsPlot <- function(conn, path.to.data, park, site, field.season
}
-#################################
-
-# 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")
+#' 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) ~ "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",
+ 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", "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),
+ Metric %in% c("Fraction") ~ paste0(Metric, ": ", Category),
+ TRUE ~ NA_character_))
+
+ return(bmi)
+}
diff --git a/R/calculations.R b/R/calculations.R
index cd389e4..c913f96 100644
--- a/R/calculations.R
+++ b/R/calculations.R
@@ -25,65 +25,62 @@ 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(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")) %>%
- 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(conn, path.to.data, park, site, field.season, data.sour
#' 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(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")) %>%
- 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(conn, path.to.data, park, site, field.season, data.so
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 9effcf3..6a45a09 100644
--- a/R/chem-qc.R
+++ b/R/chem-qc.R
@@ -1,29 +1,24 @@
#' 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(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 %>%
- filter(Flag %in% c("I", "W", "C")) %>%
- select(SampleFrame, SiteCode, SiteName, FieldSeason, VisitDate, Characteristic, CharacteristicLabel, Unit, LabValue, SampleType, Flag, FlagNote) %>%
- arrange(SampleFrame, VisitDate, SiteCode)
+ 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(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) %>%
+ 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(conn, path.to.data, park, site, field.season, data.so
}
- 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(conn, path.to.data, park, site, field.season, data.so
#' 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(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) %>%
+ 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(conn, path.to.data, park, site, field.season, data.
}
- 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(conn, path.to.data, park, site, field.season, data.
#' 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(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 %>%
- 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(conn, path.to.data, park, site, field.season, data
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(conn, path.to.data, park, site, field.season, data
#' 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(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")) %>%
+ 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(conn, path.to.data, park, site, field.season, data.source
#' 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(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")) %>%
+ 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(conn, path.to.data, park, site, field.season, data.sour
#' 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(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")) %>%
+ 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)
@@ -310,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))
@@ -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(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 %>%
- 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(conn, path.to.data, park, site, field.season, data.source
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(conn, path.to.data, park, site, field.season, data.source
#' 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(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") %>%
+ 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(conn, path.to.data, park, site, field.season, data.source =
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)
@@ -406,31 +364,26 @@ qcChemML <- function(conn, path.to.data, park, site, field.season, data.source =
}
-#' 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 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(conn, path.to.data, park, site, field.season, data.source = "database") {
+ChemFormatted <- 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") %>%
+ chem.anc.rows <- chem |>
+ dplyr::filter(Characteristic == "ALK2") |>
dplyr::mutate(Characteristic = "ANC",
CharacteristicLabel = "Acid neutralizing capacity",
Unit = "ueq/L",
@@ -438,58 +391,72 @@ ChemANC <- function(conn, path.to.data, park, site, field.season, data.source =
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 %<>% 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)
}
#' 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(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 <- ChemFormatted(park = park, site = site, field.season = field.season)
- chem.lake.anc <- chem.anc %>%
- filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Lake", Characteristic == "ANC")
+ chem.lake.anc <- chem.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, 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,
+ color = SiteShort,
+ group = SiteShort)) +
+ ggplot2::geom_point() +
+ 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::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()) +
+ khroma::scale_color_muted()
return(chem.lake.anc.plot)
@@ -497,46 +464,50 @@ ChemLakeANCPlot <- function(conn, path.to.data, park, site, field.season, data.s
#' 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(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 <- ChemFormatted(park = park, site = site, field.season = field.season)
- chem.stream.anc <- chem.anc %>%
- filter(VisitType == "Primary", SampleType == "Routine", SampleFrame == "Stream", Characteristic == "ANC")
+ chem.stream.anc <- chem.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, 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,
+ color = SiteShort,
+ group = SiteShort)) +
+ ggplot2::geom_point() +
+ 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 = "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()) +
+ khroma::scale_color_muted()
return(chem.stream.anc.plot)
@@ -550,37 +521,100 @@ 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 <- 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))
+ 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,
- 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())
+ 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(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",
+ 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_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
@@ -588,13 +622,16 @@ 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 <- 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)) %>%
+ lake.nut.bar <- 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))))
@@ -602,23 +639,24 @@ ChemLakeNutrientBarPlot <- function(conn, path.to.data, 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"), dplyr::desc(Characteristic_f))) |>
+ dplyr::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", "lightskyblue", "firebrick4", "lightpink2"))
return(lake.nut.bar.plot)
@@ -632,37 +670,99 @@ 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 <- 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 <- 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$Characteristic_f = factor(lake.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2"))
+ 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, 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())
+ 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(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",
+ 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()) +
+ 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
@@ -670,36 +770,98 @@ 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 <- 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))
+ 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, 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())
+ 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(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",
+ 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_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
@@ -707,12 +869,15 @@ 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 <- 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)) %>%
+ stream.nut.bar <- 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))))
@@ -720,23 +885,24 @@ ChemStreamNutrientBarPlot <- function(conn, path.to.data, park, site, field.seas
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, 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", "lightskyblue", "firebrick4", "lightpink2"))
return(stream.nut.bar.plot)
@@ -749,32 +915,93 @@ 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 <- 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 <- 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$Characteristic_f = factor(stream.ion$Characteristic, levels = c("Na", "Mg", "K", "Ca", "SO4-S", "Cl", "ALK2"))
+ 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, 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())
+ 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(Ion),
+ cols = ggplot2::vars(SiteShort),
+ scales = "free_y") +
+ ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90)) +
+ 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()) +
+ 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)
+
+}
diff --git a/R/clarity-qc.R b/R/clarity-qc.R
index fe69b70..f4f4ee1 100644
--- a/R/clarity-qc.R
+++ b/R/clarity-qc.R
@@ -1,30 +1,22 @@
#' 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(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)
@@ -32,32 +24,24 @@ qcSecchiGTDepth <- function(conn, path.to.data, park, site, field.season, data.s
#' 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(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)
@@ -65,32 +49,24 @@ qcLakeDryMeasurementsExist <- function(conn, path.to.data, park, site, field.sea
#' 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(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)
@@ -98,32 +74,24 @@ qcLakeNotDryMeasurementsMissing <- function(conn, path.to.data, park, site, fiel
#' 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(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..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(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 <- visit.data %>%
- dplyr::select(Park, Subunit, SiteShort, SiteCode, SiteName, SampleFrame, VisitDate, FieldSeason, VisitType, MonitoringStatus) %>%
- dplyr::filter(VisitType == "Primary", SiteCode != "GRBA_S_BAKR2") %>%
+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") |>
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,94 +32,92 @@ 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(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")
-
- visit.DPL <- visit %>%
- dplyr::rename(Visit.DPL = DataProcessingLevel) %>%
+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) |>
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) %>%
- dplyr::distinct()
- bmi.DPL <- bmi %>%
- dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, VisitType, DPL) %>%
- dplyr::rename(BMI.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()
- channel.DPL <- channel %>%
- dplyr::select(SiteCode, SiteName, VisitDate, FieldSeason, DPL) %>%
- dplyr::rename(Channel.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) |>
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,145 +129,147 @@ 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(conn, path.to.data, park, site, field.season, data.source = "database") {
-
- 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.long <- wt %>%
- dplyr::filter(Approval == "Approved") %>%
- dplyr::mutate(Date = as.Date(DateTime, format = "%Y-%m-%d", tz = "America/Los_Angeles")) %>%
+WqDailyMeanLong <- function(park, site, field.season) {
+
+ 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),
+ 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 = 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")) %>%
+ 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),
+ 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 = 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")) %>%
+ 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),
+ 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 = 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")) %>%
+ 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),
+ 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 = 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")) %>%
+ 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),
+ 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 = 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)
- 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() %>%
+ 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")) %>%
- 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)
@@ -281,31 +279,26 @@ WqDailyMeanLong <- function(conn, path.to.data, park, site, field.season, data.s
#' 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(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")) %>%
+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",
@@ -316,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)
@@ -326,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(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 %>%
+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,
@@ -358,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, 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)
@@ -375,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(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 %>%
+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 = 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)) %>%
- 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)
@@ -417,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(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 %>%
+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 {
@@ -581,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,
@@ -597,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,
@@ -605,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)
@@ -621,37 +599,32 @@ 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(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 %>%
+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)
@@ -660,40 +633,35 @@ 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(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 %>%
+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"))
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..8663f80 100644
--- a/R/levels-qc.R
+++ b/R/levels-qc.R
@@ -1,32 +1,28 @@
-#' 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
#'
-#' @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(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)
+ 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,73 +33,121 @@ SurveyPointElevation <- function(conn, path.to.data, park, site, field.season, d
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() %>%
- dplyr::filter(!(SiteShort == "DEAD0" & FieldSeason == "2021" & SurveyPoint == "WS"))
+ 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")) |>
+ dplyr::filter(VisitType == "Primary") |>
+ dplyr::select(-c(VisitType, DPL, SurveyPoint)) |>
+ 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)
}
+#' 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::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, 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(AuthoritativeBenchmark == Benchmark ~ GivenElevation_ft - MeanHeight_ft,
+ TRUE ~ NA)) |>
+ dplyr::group_by(SiteCode, FieldSeason) |>
+ tidyr::fill(Offset_ft) |>
+ dplyr::ungroup() |>
+ dplyr::mutate(Elevation_ft = dplyr::case_when(AuthoritativeBenchmark == Benchmark ~ GivenElevation_ft,
+ TRUE ~ 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(Elevation_ft, .after = "Benchmark")
+
+ return(elevs)
+
+}
+
#' Calculates lake level elevations
#'
#' @inheritParams ReadAndFilterData
@@ -111,19 +155,14 @@ SurveyPointElevation <- function(conn, path.to.data, park, site, field.season, d
#' @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(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 +180,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")
+ import <- 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(
@@ -156,43 +195,43 @@ LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, d
FieldSeason = character(),
VisitType = character(),
SurveyType = character(),
- FinalElevation_ft = double(),
+ Elevation_ft = double(),
ClosureError_ft = double(),
BenchmarkUsed = logical()
)
} else {
- survey <- SurveyPointElevation(conn, path.to.data, park, site, field.season, data.source) %>%
- 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") %>%
- dplyr::relocate(FinalElevation_ft, .after = "SurveyType")
+ BenchmarkUsed = NA_character_) |>
+ dplyr::select(-Benchmark) |>
+ dplyr::relocate(Elevation_ft, .after = "SurveyType") |>
+ dplyr::relocate(ClosureError_ft, .after = "Elevation_ft")
}
- 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() %>%
- dplyr::mutate(BenchmarkUsed = Benchmark,
+ 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() |>
+ 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, VisitType, SurveyType, FinalElevation_ft, ClosureError_ft, BenchmarkUsed) %>%
- unique()
+ SurveyType = "String") |>
+ 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"),
- ClosureError_m = measurements::conv_unit(ClosureError_ft, "ft", "m")) %>%
+ lake_elevation <- rbind(string, survey) |>
+ dplyr::filter((FieldSeason == "2018" & SurveyType == "Digital Level") | FieldSeason != "2018") |>
+ 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))
return(lake_elevation)
}
@@ -202,65 +241,106 @@ LakeSurfaceElevation <- function(conn, path.to.data, park, site, field.season, d
#' @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)
+#' qcBenchmarkConsistency()
+#' qcBenchmarkConsistency(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019"))
#' }
-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)
-
- 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()) %>%
- dplyr::ungroup()
+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.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(Elevation_ft),
+ StDev_ft = sd(Elevation_ft),
+ Count = dplyr::n()) |>
+ dplyr::ungroup() |>
+ tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left")
if (!is.na(sd_cutoff)) {
- lvls %<>% dplyr::filter(StDevElevation_ft >= sd_cutoff)
+ lvls <- lvls |>
+ 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 = Elevation_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 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(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") %>%
- dplyr::group_by(Park, SiteShort, SiteCode, SiteName, VisitDate, FieldSeason, VisitType, Benchmark) %>%
+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)) {
- str_survey %<>%
+ str_survey <- str_survey
dplyr::filter(StDevHeight_ft >= sd_cutoff)
}
@@ -270,33 +350,28 @@ qcStringSurveyHeights <- function(conn, path.to.data, park, site, field.season,
#' 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
#'
-#' @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(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") %>%
- 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) %>%
+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) |>
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 +381,43 @@ qcStringSurveyElevations <- function(conn, path.to.data, park, site, field.seaso
#' 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(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) %>%
- dplyr::rename(R_Elev_ft = FinalCorrectedElevation_ft)
+ r_elevs_data <- r_elevs |>
+ 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) %>%
+ 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")) |>
+ 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 +426,37 @@ qcElevationDiscrepancies <- function(conn, path.to.data, park, site, field.seaso
#' 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(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")
-
- 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)) %>%
+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)) |>
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::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,38 +472,50 @@ qcClosureErrorDiscrepancies <- function(conn, path.to.data, park, site, field.se
#'
#' @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(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) %>%
- dplyr::filter(Benchmark != "Water Surface") %>%
- tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left")
+PlotBenchmarkElevation <- function(park, site, field.season, include.title = TRUE, plotly = FALSE) {
+ str <- StringSurveyElevation(park = park, site = site, field.season = field.season) |>
+ dplyr::select(-c(StDev_ft, Count)) |>
+ dplyr::mutate(Method = "String")
- ptol_muted_6 <- c("#CC6677", "#332288", "#DDCC77", "#117733", "#88CCEE", "#882255")
+ dl <- SurveyPointElevation(park = park, site = site, field.season = field.season) |>
+ dplyr::select(-c(ClosureError_ft)) |>
+ dplyr::filter(Benchmark != "Water Surface") |>
+ dplyr::mutate(Method = "Digital Level")
- 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()
+ lvls <- rbind(str, dl) |>
+ tidyr::separate(Benchmark, c(NA, "Benchmark"), sep = "-", fill = "left") |>
+ tidyr::complete(FieldSeason, tidyr::nesting(Park, SiteShort, SiteCode, SiteName, Benchmark, Method))
- if (plotly) {
- plt <- plotly::ggplotly(plt, tooltip = "text")
- }
+ ptol_muted_6 <- c("#CC6677", "#332288", "#DDCC77", "#117733", "#88CCEE", "#882255")
+
+ plt <- ggplot2::ggplot(data = lvls,
+ ggplot2::aes(x = FieldSeason,
+ y = Elevation_ft,
+ color = Benchmark,
+ group = interaction(Benchmark, Method, SiteName),
+ text = paste0("Field Season: ", FieldSeason, "
",
+ "Benchmark: ", Benchmark, "
",
+ "Elevation (ft): ", round(Elevation_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)
}
@@ -456,22 +529,20 @@ PlotBenchmarkElevation <- function(conn, path.to.data, park, site, field.season,
#'
#' @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(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)) %>%
- 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,
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)") +
@@ -479,8 +550,8 @@ PlotLakeSurfaceElevation <- function(conn, path.to.data, park, site, field.seaso
group = SiteName,
text = paste0("Field Season: ", FieldSeason, "
",
"Survey Type: ", SurveyType, "
",
- "Elevation (ft): ", round(FinalElevation_ft, 2))) +
- ggplot2::geom_point(ggplot2::aes()) +
+ "Elevation (ft): ", round(Elevation_ft, 2))) +
+ ggplot2::geom_point(size = 2.2) +
ggplot2::geom_line(linewidth = 1) +
ggplot2::scale_shape_discrete(na.translate = FALSE) +
khroma::scale_color_muted()
@@ -491,3 +562,51 @@ PlotLakeSurfaceElevation <- function(conn, path.to.data, park, site, field.seaso
return(plt)
}
+
+#' Plot lake levels determined by all benchmarks where string method was used
+#'
+#' @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
+#'
+#' @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/R/utils.R b/R/utils.R
index b8a92fc..506a17a 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -1,11 +1,45 @@
-#' Open a Connection to the MOJN Streams and Lakes Database
+#' @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 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()}.
#' @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
@@ -16,7 +50,7 @@
#' }
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)
@@ -27,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)
}
@@ -59,9 +96,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(
@@ -142,7 +179,7 @@ GetColSpec <- function() {
NonInsectTaxaCount = readr::col_integer(),
NonInsectAbundance = readr::col_integer(),
.default = readr::col_character()
- ),
+ ),
Channel = readr::cols(
VisitDate = readr::col_date(),
.default = readr::col_character()
@@ -220,110 +257,250 @@ GetColSpec <- function() {
return(col.spec)
}
-#' Get column specifications for Aquarius data that have been written to csv.
+#' 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(
+ 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(),
+ LabCount = readr::col_integer(),
+ 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()
+ ),
+ 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 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.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
-#'
-#' @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.
+#' Read data from the Aquarius database
#'
-#' @details \code{data.name} options are: TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature
+#' @return A list of tibbles
#'
-ReadAquarius <- function(conn, data.name) {
+ReadAquarius <- function(...) {
+ conn <- OpenDatabaseConnection(...)
+
if (!isS4(conn$aquarius)) {
stop("Aquarius connection does not exist.")
}
+
timeseries <- conn$aquarius
- 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"))
+ 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)
+ }
- aq_identifier <- identifiers[identifiers$data_name == data.name, ]$identifier
- aq_col_name <- identifiers[identifiers$data_name == data.name, ]$col_name
+ ph_data <- list(ph_data)
+ names(ph_data) <- "TimeseriespH"
- for (location in sites) {
- site.imp <- timeseries$getTimeSeriesData(paste0(aq_identifier, location))
+ 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)
+ }
- site.data <- site.imp$Points
+ sc_data <- list(sc_data)
+ names(sc_data) <- "TimeseriesSpCond"
- site.data
+ 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)
+ }
- # site.imp <- fetchaquarius::getTimeSeries(paste0(aq_identifier, location))
+ domgl_data <- list(domgl_data)
+ names(domgl_data) <- "TimeseriesDOmgl"
- # 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)
+ 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)
+ }
- 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) %>%
+ 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"
- site.data$DateTime <- lubridate::ymd_hms(site.data$DateTime, tz = "America/Los_Angeles", quiet = TRUE)
+ data <- c(wt_data, ph_data, sc_data, domgl_data, dopct_data, q_data, wl_data)
- site.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)) %>%
- 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)
-}
+ lubridate::year(DateTime) + 1))
+ })
+ CloseDatabaseConnection(conn)
+ 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,107 +563,28 @@ 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"}.
-#' @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(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)
-
- if (!(data.source %in% c("database", "local"))) {
- stop("Please choose either 'database' or 'local' for data.source")
- }
-
- 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")
- }
+ReadAndFilterData <- function(park, site, field.season, data.name) {
+ filtered.data <- get_data(data.name)
+
+ if (!missing(field.season)) {
+ field.season <- as.character(field.season)
}
if (!missing(park)) {
filtered.data %<>%
- dplyr::filter(Park == park)
+ 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"))
}
@@ -494,7 +592,7 @@ ReadAndFilterData <- function(conn, path.to.data, park, site, field.season, data
if (!missing(site) & nrow(filtered.data) > 0) {
filtered.data %<>%
- dplyr::filter(SiteCode %in% site)
+ dplyr::filter(SiteCode == site)
if (nrow(filtered.data) == 0) {
warning(paste0(data.name, ": Data are not available for the site specified"))
@@ -557,20 +655,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)
}
@@ -580,7 +678,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")
@@ -596,30 +694,27 @@ 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())
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),
+ 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."))
@@ -642,10 +737,10 @@ GetRawData <- function(conn, path.to.data, park, site, field.season, data.source
#' @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")
- site %<>% dplyr::select("SiteCode", "SiteName") %>%
- unique() %>%
+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)
return(site$SiteName)
@@ -820,3 +915,234 @@ 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
+#'
+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_bmi <- fetchagol::fetchRawData(bmi_url, agol_username)
+ raw_bmi <- fetchagol::cleanData(raw_bmi)
+
+ # Remove unwanted data and metadata
+ raw_bmi$data[['BMI_Metadata']] <- NULL
+ raw_bmi$metadata[['BMI_Metadata']] <- NULL
+
+ names(raw_bmi$data) <- c("BMISpecies", "BMIMetrics", "BMIVisit")
+
+ 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"))
+ })
+
+ # 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 <- fetchAndWrangleAGOL() # Change name of variable to bmi once there are more data
+ # agol <- fetchAndWrangleAGOL()$data
+
+ # data <- c(bmi, agol)
+
+ 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(...)
+ 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)
+}
+
+#' Read data from one or more CSVs
+#'
+#' @param data_path
+#'
+#' @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()
+ 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)
+}
+
+#' 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"),
+ 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
+#'
+#' @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"))
+}
diff --git a/R/wq-qc.R b/R/wq-qc.R
index e4a4520..18b9099 100644
--- a/R/wq-qc.R
+++ b/R/wq-qc.R
@@ -1,36 +1,30 @@
#' 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(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)
}
#' 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(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)
}
@@ -38,54 +32,51 @@ qcStreamWqSanity <- function(conn, path.to.data, park, site, field.season, data.
#' 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(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")
}
- 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,94 +88,87 @@ qcWqSanity <- function(conn, path.to.data, park, site, field.season, data.source
#' 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(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))
+ 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(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))
+ 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(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")
}
- 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,90 +181,81 @@ qcWqFlags <- function(conn, path.to.data, park, site, field.season, data.source
#' 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(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)
}
#' 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(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)
}
#' 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(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")
}
- 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,21 +265,18 @@ qcWqCleaned <- function(conn, path.to.data, park, site, field.season, data.sourc
#' 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(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)
}
@@ -321,33 +293,30 @@ WqPlotPHDepthProfile <- function(conn, path.to.data, park, site, field.season, i
#' @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(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)
}
#' 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(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 +328,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)
}
@@ -374,12 +343,12 @@ WqPlotTemperatureDepthProfile <- function(conn, path.to.data, park, site, field.
#' @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(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) %>%
- 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(conn, path.to.data, param, units, park, site, fie
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)
}
@@ -408,6 +378,7 @@ WqPlotDepthProfile <- function(conn, path.to.data, param, units, park, site, fie
# "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
diff --git a/man/BMIDiversityMetricsPlot.Rd b/man/BMIDiversityMetricsPlot.Rd
index a6e2f97..5b11251 100644
--- a/man/BMIDiversityMetricsPlot.Rd
+++ b/man/BMIDiversityMetricsPlot.Rd
@@ -4,27 +4,14 @@
\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{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 bb7345f..b1ea75b 100644
--- a/man/BMIFormatted.Rd
+++ b/man/BMIFormatted.Rd
@@ -2,33 +2,20 @@
% 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(
- 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{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 59bd65b..e693282 100644
--- a/man/BMIFunctionalMetricsPlot.Rd
+++ b/man/BMIFunctionalMetricsPlot.Rd
@@ -4,27 +4,14 @@
\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{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 10d32b3..3ce38e2 100644
--- a/man/BMIGeneralMetricsPlot.Rd
+++ b/man/BMIGeneralMetricsPlot.Rd
@@ -4,27 +4,14 @@
\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{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
index 475b748..ad696e2 100644
--- a/man/BMILong.Rd
+++ b/man/BMILong.Rd
@@ -2,35 +2,27 @@
% Please edit documentation in R/bmi-qc.R
\name{BMILong}
\alias{BMILong}
-\title{Pivot BMI data to long format}
+\title{Pivot BMI data to long format (Deprecated data! Use for QC purposes only)}
\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{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
+Pivot BMI data to long format (Deprecated data! Use for QC purposes only)
}
\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)
+BMILong()
+BMILong(site = "GRBA_S_MILL1")
+BMILong(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015")
}
}
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 23e9cd2..47f48c8 100644
--- a/man/BMITaxonomicMetricsPlot.Rd
+++ b/man/BMITaxonomicMetricsPlot.Rd
@@ -4,27 +4,14 @@
\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{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 3fb8aad..0000000
--- a/man/BMIToleranceMetricsPlot.Rd
+++ /dev/null
@@ -1,34 +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(
- 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 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/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/ChannelCharacteristics.Rd b/man/ChannelCharacteristics.Rd
index 1826e9a..f041d75 100644
--- a/man/ChannelCharacteristics.Rd
+++ b/man/ChannelCharacteristics.Rd
@@ -2,41 +2,26 @@
% 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(
- 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{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 25ef594..5ef27b9 100644
--- a/man/ChannelFLow.Rd
+++ b/man/ChannelFLow.Rd
@@ -1,42 +1,27 @@
% 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(
- 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{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 486b548..eaf8788 100644
--- a/man/ChannelSubstrate.Rd
+++ b/man/ChannelSubstrate.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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
deleted file mode 100644
index fcc8e64..0000000
--- a/man/ChemANC.Rd
+++ /dev/null
@@ -1,35 +0,0 @@
-% 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)}
-\usage{
-ChemANC(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, SampleFrame, VisitDate, VisitType, SampleCollectionMethod, Characteristic, CharacteristicLabel, LabValue, ReportingGroup, SampleType, Flag, FlagNote, DPL, Unit
-}
-\description{
-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)
-}
-}
diff --git a/man/ChemFormatted.Rd b/man/ChemFormatted.Rd
new file mode 100644
index 0000000..0ed1ab5
--- /dev/null
+++ b/man/ChemFormatted.Rd
@@ -0,0 +1,27 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/chem-qc.R
+\name{ChemFormatted}
+\alias{ChemFormatted}
+\title{Calculate acid neutralizing capacity (ANC) from alkalinity (ALK2) and fill missing years with NAs for ease of plotting}
+\usage{
+ChemFormatted(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 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) and fill missing years with NAs for ease of plotting
+}
+\examples{
+\dontrun{
+ChemANC()
+ChemANC(site = "GRBA_L_DEAD0", field.season = "2018")
+}
+}
diff --git a/man/ChemLakeANCPlot.Rd b/man/ChemLakeANCPlot.Rd
index 099a64e..da35f51 100644
--- a/man/ChemLakeANCPlot.Rd
+++ b/man/ChemLakeANCPlot.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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/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/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/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/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/ChemStreamANCPlot.Rd b/man/ChemStreamANCPlot.Rd
index 2e930ff..6d06503 100644
--- a/man/ChemStreamANCPlot.Rd
+++ b/man/ChemStreamANCPlot.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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/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/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/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/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/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/GetRawData.Rd b/man/GetRawData.Rd
index 2256ce7..1a52bef 100644
--- a/man/GetRawData.Rd
+++ b/man/GetRawData.Rd
@@ -4,30 +4,17 @@
\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{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/LakeSurfaceElevation.Rd b/man/LakeSurfaceElevation.Rd
index a8d32f6..1ffd820 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.
@@ -34,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 a8d50af..d729302 100644
--- a/man/LakeWqMedian.Rd
+++ b/man/LakeWqMedian.Rd
@@ -4,30 +4,17 @@
\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{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/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..726442f 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.}
@@ -40,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 8015ea8..05593f6 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.}
@@ -40,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/PlotStringComparisons.Rd b/man/PlotStringComparisons.Rd
new file mode 100644
index 0000000..2f51963
--- /dev/null
+++ b/man/PlotStringComparisons.Rd
@@ -0,0 +1,27 @@
+% 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{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
+}
+\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/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/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 0df2aab..fc6b373 100644
--- a/man/ReadAndFilterData.Rd
+++ b/man/ReadAndFilterData.Rd
@@ -4,29 +4,15 @@
\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.}
}
\value{
@@ -36,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
index 39831ef..0d86daa 100644
--- a/man/ReadAquarius.Rd
+++ b/man/ReadAquarius.Rd
@@ -2,21 +2,13 @@
% Please edit documentation in R/utils.R
\name{ReadAquarius}
\alias{ReadAquarius}
-\title{Read Streams and Lakes data from Aquarius}
+\title{Read data from the Aquarius database}
\usage{
-ReadAquarius(conn, data.name)
-}
-\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.}
+ReadAquarius(...)
}
\value{
-A tibble of Aquarius data, wrangled and formatted.
+A list of tibbles
}
\description{
-Read Streams and Lakes data from Aquarius
-}
-\details{
-\code{data.name} options are: TimeseriesDO, TimeseriesDOSat, TimeseriespH, TimeseriesSpCond, TimeseriesTemperature
+Read data from the Aquarius database
}
diff --git a/man/ReadCSV.Rd b/man/ReadCSV.Rd
new file mode 100644
index 0000000..1ba7b61
--- /dev/null
+++ b/man/ReadCSV.Rd
@@ -0,0 +1,22 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utils.R
+\name{ReadCSV}
+\alias{ReadCSV}
+\title{Read data from one or more CSVs}
+\usage{
+ReadCSV(data_path)
+}
+\arguments{
+\item{data_path}{}
+}
+\value{
+A list of data frames
+}
+\description{
+Read data from one or more CSVs
+}
+\examples{
+\dontrun{
+ReadCSV("path/to/csv/folder")
+}
+}
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..cf06962 100644
--- a/man/StreamWqMedian.Rd
+++ b/man/StreamWqMedian.Rd
@@ -4,30 +4,17 @@
\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{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/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 2aec25a..5635505 100644
--- a/man/SurveyPointElevation.Rd
+++ b/man/SurveyPointElevation.Rd
@@ -2,42 +2,26 @@
% 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(
- 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.
+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{
- 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 ce49d29..5cd12c9 100644
--- a/man/WqDailyMean.Rd
+++ b/man/WqDailyMean.Rd
@@ -4,39 +4,24 @@
\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{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 ec43654..29a2997 100644
--- a/man/WqDailyMeanLong.Rd
+++ b/man/WqDailyMeanLong.Rd
@@ -4,39 +4,24 @@
\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.
+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 b64cb46..d0a5f9c 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,10 +26,14 @@ 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{
-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 3a3c951..fe5e12a 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,11 +28,9 @@ 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.
+ggplot or plotly object
}
\description{
Generate lake depth profile plots.
diff --git a/man/WqPlotPHDepthProfile.Rd b/man/WqPlotPHDepthProfile.Rd
index 63da24e..ed53320 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".}
@@ -29,11 +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{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 072278b..e700843 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".}
@@ -29,11 +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{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/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/fetchAndWrangleAGOL.Rd b/man/fetchAndWrangleAGOL.Rd
new file mode 100644
index 0000000..96c4a5a
--- /dev/null
+++ b/man/fetchAndWrangleAGOL.Rd
@@ -0,0 +1,26 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/utils.R
+\name{fetchAndWrangleAGOL}
+\alias{fetchAndWrangleAGOL}
+\title{Fetch BMI data from AGOL and do preliminary data wrangling}
+\usage{
+fetchAndWrangleAGOL(
+ 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
+)
+}
+\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
+}
+\description{
+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..71784b6
--- /dev/null
+++ b/man/qcBMIDiscrepancies.Rd
@@ -0,0 +1,28 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/bmi-qc.R
+\name{qcBMIDiscrepancies}
+\alias{qcBMIDiscrepancies}
+\title{BROKEN! FIX! Check for discrepancies between taxa count and abundance}
+\usage{
+qcBMIDiscrepancies(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{
+BROKEN! FIX! Check for discrepancies between taxa count and abundance
+}
+\examples{
+\dontrun{
+ qcBMIDiscrepancies()
+ qcBMIDiscrepancies(site = "GRBA_S_MILL1")
+ qcBMIDiscrepancies(site = c("GRBA_S_BAKR2", "GRBA_S_BAKR3"), field.season = "2015")
+}
+}
diff --git a/man/qcBenchmarkConsistency.Rd b/man/qcBenchmarkConsistency.Rd
new file mode 100644
index 0000000..5622b18
--- /dev/null
+++ b/man/qcBenchmarkConsistency.Rd
@@ -0,0 +1,29 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/levels-qc.R
+\name{qcBenchmarkConsistency}
+\alias{qcBenchmarkConsistency}
+\title{Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons}
+\usage{
+qcBenchmarkConsistency(park, site, field.season, sd_cutoff = NA)
+}
+\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{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
+}
+\description{
+Calculates mean and standard deviation of final corrected elevations for each benchmark across all field seasons
+}
+\examples{
+\dontrun{
+ qcBenchmarkConsistency()
+ qcBenchmarkConsistency(site = "GRBA_L_BAKR0", field.season = c("2016", "2017", "2018", "2019"))
+}
+}
diff --git a/man/qcChemFieldBlanks.Rd b/man/qcChemFieldBlanks.Rd
index 5141913..dbe4e8e 100644
--- a/man/qcChemFieldBlanks.Rd
+++ b/man/qcChemFieldBlanks.Rd
@@ -4,39 +4,24 @@
\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{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 edd2c32..5b2d1e2 100644
--- a/man/qcChemFieldDupes.Rd
+++ b/man/qcChemFieldDupes.Rd
@@ -4,39 +4,24 @@
\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{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 33752b9..6e7827e 100644
--- a/man/qcChemFlags.Rd
+++ b/man/qcChemFlags.Rd
@@ -4,39 +4,24 @@
\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{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 b48fbcf..b9370ef 100644
--- a/man/qcChemLabDupes.Rd
+++ b/man/qcChemLabDupes.Rd
@@ -4,39 +4,24 @@
\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{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 f96a81c..45e210a 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{
@@ -34,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 0261a4d..67bda9b 100644
--- a/man/qcChemML.Rd
+++ b/man/qcChemML.Rd
@@ -4,27 +4,14 @@
\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{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.
@@ -34,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 6427bbb..68fe201 100644
--- a/man/qcChemNO3NO2.Rd
+++ b/man/qcChemNO3NO2.Rd
@@ -4,39 +4,24 @@
\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{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 2f8b37d..169507c 100644
--- a/man/qcChemTDN.Rd
+++ b/man/qcChemTDN.Rd
@@ -4,39 +4,24 @@
\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{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 e3dbfb2..56bdce3 100644
--- a/man/qcChemTDP.Rd
+++ b/man/qcChemTDP.Rd
@@ -4,39 +4,24 @@
\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{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 a6b0d74..e2a8b8b 100644
--- a/man/qcClosureErrorDiscrepancies.Rd
+++ b/man/qcClosureErrorDiscrepancies.Rd
@@ -4,40 +4,24 @@
\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{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 12390c4..29e7c92 100644
--- a/man/qcDPLCheck.Rd
+++ b/man/qcDPLCheck.Rd
@@ -4,39 +4,24 @@
\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
+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 9c3362f..42b2758 100644
--- a/man/qcElevationDiscrepancies.Rd
+++ b/man/qcElevationDiscrepancies.Rd
@@ -4,40 +4,24 @@
\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{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 461d03e..2490aa1 100644
--- a/man/qcLakeDryMeasurementsExist.Rd
+++ b/man/qcLakeDryMeasurementsExist.Rd
@@ -4,40 +4,24 @@
\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{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 2310076..cebc044 100644
--- a/man/qcLakeNotDryMeasurementsMissing.Rd
+++ b/man/qcLakeNotDryMeasurementsMissing.Rd
@@ -4,27 +4,14 @@
\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{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.
@@ -34,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 523b56b..fe6fba2 100644
--- a/man/qcLakeWqCleaned.Rd
+++ b/man/qcLakeWqCleaned.Rd
@@ -4,30 +4,17 @@
\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{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 5457ca3..7663ab8 100644
--- a/man/qcLakeWqFlags.Rd
+++ b/man/qcLakeWqFlags.Rd
@@ -4,30 +4,17 @@
\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{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 ac5d6bb..164f48d 100644
--- a/man/qcLakeWqSanity.Rd
+++ b/man/qcLakeWqSanity.Rd
@@ -4,30 +4,17 @@
\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{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 f7850ec..191b2a8 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
@@ -34,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 f4dbca3..0c13090 100644
--- a/man/qcSecchiDepthMissing.Rd
+++ b/man/qcSecchiDepthMissing.Rd
@@ -4,40 +4,24 @@
\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{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 052cd60..155a0a2 100644
--- a/man/qcSecchiGTDepth.Rd
+++ b/man/qcSecchiGTDepth.Rd
@@ -4,27 +4,14 @@
\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{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.
@@ -34,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 1e1a80e..fb53ddb 100644
--- a/man/qcStreamWqCleaned.Rd
+++ b/man/qcStreamWqCleaned.Rd
@@ -4,30 +4,17 @@
\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{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 0ccb147..52e0b6b 100644
--- a/man/qcStreamWqFlags.Rd
+++ b/man/qcStreamWqFlags.Rd
@@ -4,30 +4,17 @@
\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{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 b519161..c00d523 100644
--- a/man/qcStreamWqSanity.Rd
+++ b/man/qcStreamWqSanity.Rd
@@ -4,30 +4,17 @@
\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{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
new file mode 100644
index 0000000..268be09
--- /dev/null
+++ b/man/qcStringSurveyElevations.Rd
@@ -0,0 +1,29 @@
+% 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(park, site, field.season, sd_cutoff = NA)
+}
+\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{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
+}
+\description{
+Calculates mean and standard deviation of string survey lake level elevations for each year
+}
+\examples{
+\dontrun{
+ qcStringSurveyElevations()
+ qQcStringSurveyElevations(site = "GRBA_L_BAKR0", field.season = c("2016", "2017"))
+}
+}
diff --git a/man/qcStringSurveyHeights.Rd b/man/qcStringSurveyHeights.Rd
new file mode 100644
index 0000000..ae458d8
--- /dev/null
+++ b/man/qcStringSurveyHeights.Rd
@@ -0,0 +1,29 @@
+% 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(park, site, field.season, sd_cutoff = NA)
+}
+\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{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
+}
+\description{
+Calculates mean and standard deviation of string survey heights for each benchmark
+}
+\examples{
+\dontrun{
+ qcStringSurveyHeights()
+ qcStringSurveyHeights(site = "GRBA_L_BAKR0", field.season = c("2016", "2017"))
+}
+}
diff --git a/man/qcWqCleaned.Rd b/man/qcWqCleaned.Rd
new file mode 100644
index 0000000..4bfa9e2
--- /dev/null
+++ b/man/qcWqCleaned.Rd
@@ -0,0 +1,23 @@
+% 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(park, site, field.season, wq.type)
+}
+\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{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.}
+}
+\value{
+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 e9db358..e11c2a9 100644
--- a/man/qcWqCompleteness.Rd
+++ b/man/qcWqCompleteness.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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 7e1a6b2..278cc89 100644
--- a/man/qcWqCompletenessPlot.Rd
+++ b/man/qcWqCompletenessPlot.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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
new file mode 100644
index 0000000..ed37b67
--- /dev/null
+++ b/man/qcWqFlags.Rd
@@ -0,0 +1,23 @@
+% 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(park, site, field.season, wq.type)
+}
+\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{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.}
+}
+\value{
+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 a83d58c..94d016e 100644
--- a/man/qcWqGrades.Rd
+++ b/man/qcWqGrades.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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 35433bc..4c70f99 100644
--- a/man/qcWqGradesLong.Rd
+++ b/man/qcWqGradesLong.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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 3430ba8..0d50695 100644
--- a/man/qcWqGradesPlot.Rd
+++ b/man/qcWqGradesPlot.Rd
@@ -4,27 +4,14 @@
\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{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
@@ -34,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
new file mode 100644
index 0000000..5fb845b
--- /dev/null
+++ b/man/qcWqSanity.Rd
@@ -0,0 +1,23 @@
+% 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(park, site, field.season, wq.type)
+}
+\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{wq.type}{Either "stream" or "lake". Indicates whether to use stream or lake water quality data.}
+}
+\value{
+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
+}
diff --git a/man/writeBMI.Rd b/man/writeBMI.Rd
new file mode 100644
index 0000000..afb4e7e
--- /dev/null
+++ b/man/writeBMI.Rd
@@ -0,0 +1,36 @@
+% 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"),
+ ...
+)
+}
+\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
+}