From ca2c759968d6efc0bc0a328c59e8e77f3e1b8fe5 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Thu, 3 Aug 2017 15:36:39 -0500 Subject: [PATCH] Getting in more tests and less warnings --- R/plotFluxHist.R | 3 +- man/estFNyears.Rd | 2 + man/plotConcHist.Rd | 4 +- man/plotFluxHist.Rd | 2 + man/tableChange.Rd | 2 + man/tableChangeSingle.Rd | 7 ++- man/tableResults.Rd | 2 + tests/testthat/tests_flow_normalization.R | 20 +++++++- tests/testthat/tests_utils.R | 62 +++++++++++++++++++++++ 9 files changed, 99 insertions(+), 5 deletions(-) diff --git a/R/plotFluxHist.R b/R/plotFluxHist.R index a8734cb3..a9af3144 100644 --- a/R/plotFluxHist.R +++ b/R/plotFluxHist.R @@ -37,13 +37,14 @@ #' yearEnd <- 2010 #' eList <- Choptank_eList #' # Water year: +#' \dontrun{ #' plotFluxHist(eList) #' plotFluxHist(eList, yearStart, yearEnd, fluxUnit = 1) #' plotFluxHist(eList, yearStart, yearEnd, fluxUnit = 'kgDay') #' # Graphs consisting of Jun-Aug #' eList <- setPA(eList, paStart=6,paLong=3) #' plotFluxHist(eList) -#' \dontrun{ +#' #' # Flow normalized (excluding extremes from 2003-04): #' yearVector <- c(1980:2002, 2005:2015) #' plotFluxHist(eList, flowNormYears=yearVector) diff --git a/man/estFNyears.Rd b/man/estFNyears.Rd index db49f77c..001b82ee 100644 --- a/man/estFNyears.Rd +++ b/man/estFNyears.Rd @@ -10,6 +10,8 @@ estFNyears(eList, years, waterYear = TRUE) \item{eList}{named list with at least the Daily, Sample, and INFO dataframes} \item{years}{vector of years} + +\item{waterYear}{logical. Should years be water years (\code{TRUE}) or calendar years (\code{FALSE})} } \description{ Estimates for flow normalization by year diff --git a/man/plotConcHist.Rd b/man/plotConcHist.Rd index cba2ee02..de838701 100644 --- a/man/plotConcHist.Rd +++ b/man/plotConcHist.Rd @@ -60,15 +60,17 @@ Although there are a lot of optional arguments to this function, most are set to yearStart <- 2001 yearEnd <- 2010 eList <- Choptank_eList + # Water year: plotConcHist(eList, yearStart, yearEnd) # Graphs consisting of Jun-Aug eList <- setPA(eList, paStart=6,paLong=3) plotConcHist(eList) - +\dontrun{ flowNormYears <- c(1985:2002,2006:2010) plotConcHist(eList, flowNormYears=flowNormYears) } +} \seealso{ \code{\link{setupYears}}, \code{\link{genericEGRETDotPlot}} } diff --git a/man/plotFluxHist.Rd b/man/plotFluxHist.Rd index 0c54d427..54b41cd0 100644 --- a/man/plotFluxHist.Rd +++ b/man/plotFluxHist.Rd @@ -69,10 +69,12 @@ plotFluxHist(eList, yearStart, yearEnd, fluxUnit = 'kgDay') # Graphs consisting of Jun-Aug eList <- setPA(eList, paStart=6,paLong=3) plotFluxHist(eList) +\dontrun{ # Flow normalized (excluding extremes from 2003-04): yearVector <- c(1980:2002, 2005:2015) plotFluxHist(eList, flowNormYears=yearVector) } +} \seealso{ \code{\link{setupYears}} } diff --git a/man/tableChange.Rd b/man/tableChange.Rd index a6be69e8..680d58fe 100644 --- a/man/tableChange.Rd +++ b/man/tableChange.Rd @@ -27,6 +27,7 @@ they can be set by the program to be the final year of the record and a set of y \examples{ eList <- Choptank_eList # Water Year: +\dontrun{ tableChange(eList, fluxUnit=6, yearPoints=c(2001,2005,2008,2009)) tableChange(eList, fluxUnit=9) tableChange(eList, fluxUnit=9, flowNormYear=c(2001:2006, 2008:2009)) @@ -34,5 +35,6 @@ tableChange(eList, fluxUnit=9, flowNormYear=c(2001:2006, 2008:2009)) eList <- setPA(eList, paStart=12,paLong=3) tableChange(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009)) } +} \keyword{statistics} \keyword{water-quality} diff --git a/man/tableChangeSingle.Rd b/man/tableChangeSingle.Rd index 68fc073e..a68bea43 100644 --- a/man/tableChangeSingle.Rd +++ b/man/tableChangeSingle.Rd @@ -33,16 +33,19 @@ they can be set by the program to be the final year of the record and a set of y } \examples{ eList <- Choptank_eList +\dontrun{ # Water Year: #This returns concentration ASCII table in the console: tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), flux=FALSE) -tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), +#Returns a data frame: +change <- tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), flowNormYears=c(2003:2004, 2006:2009), flux=FALSE) #This returns flux values ASCII table in the console -tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), flux=TRUE) +df <- tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), flux=TRUE) # Winter: eList <- setPA(eList, paStart=12,paLong=3) tableChangeSingle(eList, fluxUnit=6,yearPoints=c(2001,2005,2008,2009), flux=FALSE) } +} \keyword{statistics} \keyword{water-quality} diff --git a/man/tableResults.Rd b/man/tableResults.Rd index 3ad311fa..6089b99e 100644 --- a/man/tableResults.Rd +++ b/man/tableResults.Rd @@ -30,6 +30,7 @@ mean flux, and flow-normalized flux. \examples{ eList <- Choptank_eList # Water Year: +\dontrun{ tableResults(eList, fluxUnit = 1) tableResults(eList, fluxUnit = 1, flowNormYears = c(1980:1995, 1997:2002, 2004:2011)) tableResults(eList, fluxUnit = 'kgDay', qUnit = 'cms') @@ -38,5 +39,6 @@ returnedTable <- tableResults(eList, fluxUnit = 1) eList <- setPA(eList, paLong=3,paStart=12) tableResults(eList, fluxUnit = 1) } +} \keyword{statistics} \keyword{water-quality} diff --git a/tests/testthat/tests_flow_normalization.R b/tests/testthat/tests_flow_normalization.R index f79e9bb1..3931b299 100644 --- a/tests/testthat/tests_flow_normalization.R +++ b/tests/testthat/tests_flow_normalization.R @@ -91,4 +91,22 @@ test_that("setupYears", { "Conc [mg/L]","FN Conc [mg/L]", "Flux [kg/day]","FN Flux [kg/day]"))) -}) \ No newline at end of file + eList <- Choptank_eList + tFC <- tableFlowChange(eList, istat=5, yearPoints=c(1985,1990,1995,2001,2005,2009)) + expect_true(all(names(tFC) %in% c("year1","year2","change[cfs]","slope[cfs/yr]", + "change[%]","slope[%/yr]"))) + expect_equal(tFC$`change[cfs]`[1], 7.5) + expect_equal(tFC$`slope[cfs/yr]`[1], 1.5) + expect_equal(tFC$`change[%]`[1], 6.5) + expect_equal(tFC$`slope[%/yr]`[1], 1.3) + + printReturn <- printSeries(eList, 5) + expect_true(all(names(printReturn) %in% c("years","qActual","qSmooth"))) + + expect_equal(printReturn$qActual[2], 78.3) + expect_equal(printReturn$qSmooth[2], 109) + + expect_equal(setSeasonLabelByUser(), "Water Year") + expect_equal(setSeasonLabelByUser(paStartInput = 12,paLongInput = 3), "Season Consisting of Dec Jan Feb") +}) + \ No newline at end of file diff --git a/tests/testthat/tests_utils.R b/tests/testthat/tests_utils.R index 68ed2e69..b81b9a4e 100644 --- a/tests/testthat/tests_utils.R +++ b/tests/testthat/tests_utils.R @@ -205,6 +205,46 @@ test_that("other plot functions don't error", { expect_silent(plotFluxPred(eList)) expect_true(dev_start + 1 == dev.cur()) + graphics.off() + dev_start <- dev.cur() + expect_silent(plotQTimeDaily(eList)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plotFluxQ(eList)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plotFlowSingle(eList, istat = 1)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plotFour(eList)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plotFour(eList)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plot1of15(eList, yearStart = 1995, yearEnd = 2005, qf = 1)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plotSDLogQ(eList)) + expect_true(dev_start + 1 == dev.cur()) + + graphics.off() + dev_start <- dev.cur() + expect_silent(plot15(eList = eList, yearStart = 1995, yearEnd = 2005)) + expect_true(dev_start + 1 == dev.cur()) + graphics.off() dev_start <- dev.cur() expect_silent(plotResidPred(eList)) @@ -307,4 +347,26 @@ test_that("flexPlotAddOn functions properly", { "The number of segments exceed the length of the color palette. Supply custom palette of length 32") expect_true(dev_start + 1 == dev.cur()) + startBlank <- "1995-01-01" + endBlank <- "2005-01-01" + + blank_eList <- blankTime(eList, startBlank, endBlank) + expect_is(blank_eList, "egret") + blank_daily <- getDaily(blank_eList) + expect_true(all(is.na(blank_daily$FNConc[blank_daily$Date > startBlank & + blank_daily$Date < endBlank]))) + + not_blank <- getDaily(eList) + expect_false(all(is.na(not_blank$FNConc[not_blank$Date > startBlank & + not_blank$Date < endBlank]))) + + expect_output(printFluxUnitCheatSheet(), +"The following codes apply to the fluxUnit list", ignore.case = TRUE) + + expect_output(printqUnitCheatSheet(), + "The following codes apply to the qUnit list:", ignore.case = TRUE) + + bias <- fluxBiasStat(localSample = eList$Sample) + rounded <- as.numeric(signif(bias)) + expect_equal(rounded, c(-0.0235532,-0.0235429,-0.023548)) })