diff --git a/R/egret_objects.R b/R/egret_objects.R index 396befa0..169d89f4 100644 --- a/R/egret_objects.R +++ b/R/egret_objects.R @@ -24,7 +24,11 @@ #' plotFluxQ(eList_full) as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) { - if(!all(is.na(Daily))){ + if(exists("Daily") && !all(is.na(Daily))){ + + if(!("Q" %in% names(Daily))){ + stop("Missing column 'Q' in Daily dataframe.") + } expectedCols <- c("Date","Q","LogQ","Julian","Month","Day","DecYear","MonthSeq") if(!all(expectedCols %in% names(Daily))){ @@ -40,7 +44,7 @@ as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) { } } - if(!all(is.na(Sample))){ + if(exists("Sample") && !all(is.na(Sample))){ if(any(duplicated(Sample$Date))){ message("\nThere are ",sum(duplicated(Sample$Date))," duplicated Sample dates.") } @@ -48,23 +52,14 @@ as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) { Sample <- Sample[order(Sample$Date, decreasing = FALSE),] message("\nThe Sample data frame was sorted chronologically.") } + + if(!all((c("ConcLow","ConcHigh","Uncen","ConcAve") %in% names(Sample)))){ + message("\nPlease double check that the Sample dataframe is correctly defined.") + message("\nMissing columns:", c("ConcLow","ConcHigh","Uncen","ConcAve")[!(c("ConcLow","ConcHigh","Uncen","ConcAve") %in% names(Sample))]) + } } - eList <- list(INFO=INFO, - Daily=Daily, - Sample=Sample, - surfaces=surfaces) - - if(!all(is.na(Daily)) && !("Q" %in% names(Daily))){ - stop("Missing column 'Q' in Daily dataframe.") - } - - if(!all(is.na(Sample)) && !all((c("ConcLow","ConcHigh","Uncen","ConcAve") %in% names(Sample)))){ - message("\nPlease double check that the Sample dataframe is correctly defined.") - message("\nMissing columns:", c("ConcLow","ConcHigh","Uncen","ConcAve")[!(c("ConcLow","ConcHigh","Uncen","ConcAve") %in% names(Sample))]) - } - - if(!any(c("param.units", "shortName", "paramShortName", "constitAbbrev", "drainSqKm") %in% names(INFO))){ + if(exists("INFO") && !any(c("param.units", "shortName", "paramShortName", "constitAbbrev", "drainSqKm") %in% names(INFO))){ message("\nPlease double check that the INFO dataframe is correctly defined.") } @@ -72,6 +67,11 @@ as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) { message("\nPlease double check that the surfaces matrix is correctly defined.") } + eList <- list(INFO=INFO, + Daily=Daily, + Sample=Sample, + surfaces=surfaces) + attr(eList, "param.units") <- INFO$param.units attr(eList, "shortName") <- INFO$shortName attr(eList, "paramShortName") <- INFO$paramShortName diff --git a/R/mergeReport.r b/R/mergeReport.r index 4d8db86c..b9b446d6 100644 --- a/R/mergeReport.r +++ b/R/mergeReport.r @@ -49,12 +49,12 @@ mergeReport <- function(INFO, Daily, Sample = NA, surfaces=NA, verbose = TRUE, i dataOverview(Daily, Sample) } - if(!is.na(Daily) && !("Q" %in% names(Daily))){ + if(exists("Daily") && !all(is.na(Daily)) && !("Q" %in% names(Daily))){ message("Please double check that the Daily dataframe is correctly defined.") } - if(!any(c("param.units", "shortName", "paramShortName", "constitAbbrev", "drainSqKm") %in% names(INFO))){ + if(exists("INFO") && !any(c("param.units", "shortName", "paramShortName", "constitAbbrev", "drainSqKm") %in% names(INFO))){ message("Please double check that the INFO dataframe is correctly defined.") } diff --git a/R/readUserSample.r b/R/readUserSample.r index a9b2e928..a2a378c6 100644 --- a/R/readUserSample.r +++ b/R/readUserSample.r @@ -35,7 +35,7 @@ #' @examples #' filePath <- system.file("extdata", package="EGRET") #' fileName <- 'ChoptankRiverNitrate.csv' -#' Sample <- readUserSample(filePath,fileName, separator=";",interactive=FALSE) +#' Sample <- readUserSample(filePath,fileName, separator=";",verbose=FALSE) readUserSample <- function (filePath,fileName,hasHeader=TRUE,separator=",", verbose=TRUE, interactive=NULL){ if(!is.null(interactive)) { diff --git a/docs/articles/Enhancements.html b/docs/articles/Enhancements.html index 54604c1b..5a18f0d1 100644 --- a/docs/articles/Enhancements.html +++ b/docs/articles/Enhancements.html @@ -264,7 +264,7 @@

fluxPercents
## Total Percent Change         CQTC Percent          QTC Percent 
 ##             50.68378             31.94442             18.73936
-

One final note about this output is that we can also express the flux information as yields, by dividing by the drainage area. So we can do a matrix multiplication and end up with a new object that still has concentrations in the first row but has yields in the second row. For example if we want to do yield in kg/km^2/year. We could do this. First we see pairResults and second we see pairResultsYield.

+

We can provide a nice looking table of these results as follows (with a specified number of significant digits):

knitr::kable(pairResults, digits = 4)
@@ -302,8 +302,9 @@

# note that you don't have to use the kable function from knitr to 
 # see the results, you can just give the command pairResults
-# and you will get the output, it just won't look as nice as this
-pairResultsYield <- pairResults * c(1, 1000000 / eList$INFO$drainSqKm )
+# and you will get the output, it just won't look as nice as this
+

One final note about this output is that we can also express the flux information as yields, by dividing by the drainage area. This can be very handy when looking at many watersheds. It would be nice to see how their flux trends compare on a unit area basis. To get the yields we can do a matrix multiplication and end up with a new object that still has concentrations in the first row but has yields in the second row. For example if we want to do yield in kg/km^2/year. We could do this. First we can create another data frame called pairResultsYield, and then print it as a table.

+
pairResultsYield <- pairResults * c(1, 1000000 / eList$INFO$drainSqKm )
 knitr::kable(pairResultsYield, digits = 4)
diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-6-1.png index 6cb953d7..67606360 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-6-2.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-6-2.png index 2f04de06..09ec93e9 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-6-2.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-6-2.png differ diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-7-1.png index e73c1549..0fa7143b 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-7-2.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-7-2.png index a9fe85f1..c770f225 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-7-2.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-7-2.png differ diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-8-1.png index 4bb954c5..3ecb24af 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/rResid_files/figure-html/unnamed-chunk-8-2.png b/docs/articles/rResid_files/figure-html/unnamed-chunk-8-2.png index 8de1aef6..af98ac3a 100644 Binary files a/docs/articles/rResid_files/figure-html/unnamed-chunk-8-2.png and b/docs/articles/rResid_files/figure-html/unnamed-chunk-8-2.png differ diff --git a/docs/reference/readUserSample.html b/docs/reference/readUserSample.html index b2d04758..1bf40582 100644 --- a/docs/reference/readUserSample.html +++ b/docs/reference/readUserSample.html @@ -202,7 +202,7 @@

See a

Examples

filePath <- system.file("extdata", package="EGRET") fileName <- 'ChoptankRiverNitrate.csv' -Sample <- readUserSample(filePath,fileName, separator=";",interactive=FALSE)
#> Warning: The argument 'interactive' is deprecated. Please use 'verbose' instead
+Sample<-readUserSample(filePath,fileName, separator=";",verbose=FALSE)