Skip to content

Commit

Permalink
Merge pull request #210 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
Adding a few columns to runPairs output
  • Loading branch information
ldecicco-USGS authored Feb 7, 2019
2 parents 64d6740 + 992b661 commit e69403e
Show file tree
Hide file tree
Showing 61 changed files with 1,338 additions and 1,868 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ DISCLAIMER.md
code.json
hexSticker.R
^docs$
EGRET.Rcheck
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

language: r
cache: packages
dist: trusty

matrix:
include:
Expand All @@ -27,20 +26,20 @@ repos:

env:
global:
- R_BUILD_ARGS="--no-vignettes --no-manual"
- R_CHECK_ARGS="--no-vignettes --no-manual --as-cran"
- NOT_CRAN="true"
- _R_CHECK_FORCE_SUGGESTS_=false


r_build_args: --no-build-vignettes --no-manual --no-resave-data
r_check_args: --no-build-vignettes --no-manual --as-cran
warnings_are_errors: true

r_github_packages:
- jimhester/covr

script:
- |
R CMD build .
travis_wait 20 R CMD check EGRET*tar.gz
R CMD build . --no-build-vignettes --no-manual --no-resave-data
travis_wait 20 R CMD check EGRET*tar.gz --no-build-vignettes --no-manual --as-cran
after_success:
- if [[ "${R_CODECOV}" ]]; then travis_wait 20 R -e 'covr::coveralls()'; fi
Expand Down
6 changes: 3 additions & 3 deletions R/egret_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) {
Sample=Sample,
surfaces=surfaces)

if(!is.na(Daily) && !("Q" %in% names(Daily))){
if(!all(is.na(Daily)) && !("Q" %in% names(Daily))){
stop("Missing column 'Q' in Daily dataframe.")
}

if(!is.na(Sample) && !all((c("ConcLow","ConcHigh","Uncen","ConcAve") %in% names(Sample)))){
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))])
}
Expand All @@ -68,7 +68,7 @@ as.egret <- function(INFO, Daily, Sample=NA, surfaces=NA) {
message("\nPlease double check that the INFO dataframe is correctly defined.")
}

if(!is.na(surfaces) && 14 != nrow(surfaces)){
if(exists("surfaces") && isTRUE(14 != nrow(surfaces))){
message("\nPlease double check that the surfaces matrix is correctly defined.")
}

Expand Down
2 changes: 0 additions & 2 deletions R/readNWISDaily.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' Import NWIS Daily Data for EGRET analysis
#'
#' Imports daily data from NWIS web service. This function gets the data from here: \url{https://waterservices.usgs.gov/}
#' A list of parameter codes can be found here: \url{https://nwis.waterdata.usgs.gov/nwis/pmcodes/}
#' A list of statistic codes can be found here: \url{https://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table}
#'
#' @param siteNumber character USGS site number. This is usually an 8 digit number
#' @param parameterCd character USGS parameter code. This is usually an 5 digit number.
Expand Down
2 changes: 1 addition & 1 deletion R/readNWISSample.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Import NWIS Sample Data for EGRET analysis
#'
#' Imports data from NWIS web service. This function gets the data from here: \url{https://nwis.waterdata.usgs.gov/nwis/qwdata/}
#' Imports data from NWIS web service.
#' A list of parameter and statistic codes can be found here: \url{https://help.waterdata.usgs.gov/codes-and-parameters}
#' For raw data, use \code{\link[dataRetrieval]{readNWISqw}} from the dataRetrieval package. This function will retrieve the raw data, and compress it (summing constituents). See
#' section 3.2.4 of the vignette for more details.
Expand Down
46 changes: 36 additions & 10 deletions R/runPairs.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
#' x20 \tab The results using the CQR for year 2, but using the QD for the entire period. \cr
#' x22 \tab The results for the CQR for year 2, but using the QD specified by the user for year 2. \cr
#' }
#' Additionally, there is an attribute on the data frame "Other", containing
#' a list that includes minNumObs=minNumObs, minNumUncen, windowY, windowQ,
#' windowS, wall, edgeAdjust, QStartDate, QEndDate, PercentChangeConc, and PercentChangeFlux.
#'
#' PercentChangeConc, and PercentChangeFlux are vectors with:
#' Total Percent Change is the Total Change divided by x11
#' CQTC Percent is the CQTC divided by x11
#' QTC Percent is the QTC divided by x11
#'
#' @examples
#' eList <- Choptank_eList
#' year1 <- 1985
Expand Down Expand Up @@ -321,9 +330,20 @@ runPairs <- function(eList, year1, year2, windowSide,
cDeltaTotal <- c22 - c11
cRSpart <- c20 - c10
cFDpart <- cDeltaTotal - cRSpart

fDeltaTotal <- f22 - f11
fRSpart <- f20 - f10
fFDpart <- fDeltaTotal - fRSpart

totChangePct_conc <- 100*cDeltaTotal/c11
totChangePct_flux <- 100*fDeltaTotal/f11

CQTC_percent_conc <- 100*cRSpart / c11 # CQTC Percent
QTC_percent_conc <- 100*cFDpart / c11 # Q Trend Component Percent

CQTC_percent_flux <- 100*fRSpart / f11
QTC_percent_flux <- 100*fFDpart / f11

pairResults <- as.data.frame(matrix(ncol = 7, nrow = 2))
colnames(pairResults) <- c("TotalChange", "CQTC", "QTC",
"x10", "x11", "x20", "x22")
Expand Down Expand Up @@ -352,7 +372,13 @@ runPairs <- function(eList, year1, year2, windowSide,
wall=wall,
edgeAdjust=edgeAdjust,
QStartDate = as.Date(QStartDate),
QEndDate = as.Date(QEndDate))
QEndDate = as.Date(QEndDate),
PercentChangeConc = c("Total Percent Change" = totChangePct_conc,
"CQTC Percent" = CQTC_percent_conc,
"QTC Percent" = QTC_percent_conc),
PercentChangeFlux = c("Total Percent Change" = totChangePct_flux,
"CQTC Percent" = CQTC_percent_flux,
"QTC Percent" = QTC_percent_flux))

attr(pairResults, "Other") <- Other

Expand All @@ -364,23 +390,23 @@ runPairs <- function(eList, year1, year2, windowSide,
as.character(sample1EndDate), "\n")
cat("\n Change estimates ", year2, " minus ", year1, "\n")
totChange <- format(pairResults[1, 1], digits = 3)
totChangePct <- format(100 * ((c22 - c11)/c11), digits = 2)
totChangePct_conc_f <- format(totChangePct_conc, digits = 2)
cat("\n For concentration: total change is ", totChange,
"mg/L")
cat("\n expressed as Percent Change is ", totChangePct, "%")
pctRS <- format(100 * (cRSpart/c11), digits = 2)
pctFD <- format(100 * (cFDpart/c11), digits = 2)
cat("\n expressed as Percent Change is ", totChangePct_conc_f, "%")
pctRS <- format(CQTC_percent_conc, digits = 2)
pctFD <- format(QTC_percent_conc, digits = 2)
cat("\n\n Concentration v. Q Trend Component ", pctRS, "%\n Q Trend Component ",
pctFD, "% \n\n")
totChange <- format(pairResults[2, 1], digits = 3)
totChangePct <- format(100 * ((f22 - f11)/f11), digits = 2)
totChangePct_flux_f <- format((totChangePct_flux), digits = 2)
cat("\n For flux: total change is ", totChange, "million kg/year")
cat("\n expressed as Percent Change is ", totChangePct, "%")
pctRS <- format(100 * (fRSpart/f11), digits = 2)
pctFD <- format(100 * (fFDpart/f11), digits = 2)
cat("\n expressed as Percent Change is ", totChangePct_flux_f, "%")
pctRS <- format(CQTC_percent_flux, digits = 2)
pctFD <- format(QTC_percent_flux, digits = 2)
cat("\n\n Concentration v. Q Trend Component ", pctRS, "%\n Q Trend Component ",
pctFD, "% \n\n")
print(pairResults, digits = 2)
print(pairResults[,1:7], digits = 2)
return(pairResults)

}
1 change: 0 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ knitr::opts_chunk$set(
# EGRET

[![travis](https://travis-ci.org/USGS-R/EGRET.svg?branch=master)](https://travis-ci.org/USGS-R/EGRET)
[![Build status](https://ci.appveyor.com/api/projects/status/i2hr35abwxx85vgs?svg=true)](https://ci.appveyor.com/project/ldecicco-USGS/EGRET)
[![Coverage Status](https://coveralls.io/repos/github/USGS-R/EGRET/badge.svg?branch=master)](https://coveralls.io/github/USGS-R/EGRET?branch=master)
[![status](https://img.shields.io/badge/USGS-Research-blue.svg)](https://owi.usgs.gov/R/packages.html#research)
[![CRAN version](http://www.r-pkg.org/badges/version/EGRET)](https://cran.r-project.org/package=EGRET)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ EGRET
=====

[![travis](https://travis-ci.org/USGS-R/EGRET.svg?branch=master)](https://travis-ci.org/USGS-R/EGRET)
[![Build
status](https://ci.appveyor.com/api/projects/status/i2hr35abwxx85vgs?svg=true)](https://ci.appveyor.com/project/ldecicco-USGS/EGRET)
[![Coverage
Status](https://coveralls.io/repos/github/USGS-R/EGRET/badge.svg?branch=master)](https://coveralls.io/github/USGS-R/EGRET?branch=master)
[![status](https://img.shields.io/badge/USGS-Research-blue.svg)](https://owi.usgs.gov/R/packages.html#research)
Expand Down
40 changes: 0 additions & 40 deletions appveyor.yml

This file was deleted.

Loading

0 comments on commit e69403e

Please sign in to comment.