Skip to content

Commit

Permalink
Reduce direct imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Apr 18, 2024
1 parent 70fe123 commit a680da8
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 136 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Meta/
Newstuff/
*.docx
vignettes/*.html
vignettes/*.R
vignettes/EGRET.R
vignettes/Enhancements.R
vignettes/TrendsByMonth.R
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ Copyright: This software is in the public domain because it contains materials
the United States Department of Interior. For more information, see the
official USGS copyright policy at
https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(old_usage = TRUE)
Encoding: UTF-8
23 changes: 0 additions & 23 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,12 @@ exportClasses(fluxUnit)
exportClasses(monthLabel)
exportClasses(qUnit)
import(methods)
importFrom(grDevices,colorRampPalette)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,box)
importFrom(graphics,boxplot)
importFrom(graphics,contour)
importFrom(graphics,filled.contour)
importFrom(graphics,grconvertX)
importFrom(graphics,grconvertY)
importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(graphics,segments)
importFrom(graphics,title)
importFrom(stats,aggregate)
importFrom(stats,filter)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,predict)
importFrom(stats,quantile)
importFrom(stats,reshape)
importFrom(stats,rnorm)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(utils,URLencode)
importFrom(utils,read.delim)
importFrom(utils,tail)
importFrom(utils,write.table)
27 changes: 2 additions & 25 deletions R/EGRET.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,20 @@ Extended Documentation: https://rconnect.usgs.gov/EGRET")
#'
#' @name EGRET-package
#' @docType package
#' @importFrom utils write.table
#' @importFrom utils read.delim
#' @importFrom utils URLencode
#' @importFrom utils tail
#' @importFrom stats aggregate
#' @importFrom stats lm
#' @importFrom stats median
#' @importFrom stats sd
#' @importFrom stats reshape
#' @importFrom stats filter
#' @importFrom stats rnorm
#' @importFrom stats na.omit
#'
#' @importFrom graphics abline
#' @importFrom graphics axis
#' @importFrom graphics box
#' @importFrom graphics boxplot
#' @importFrom graphics contour
#' @importFrom graphics filled.contour
#' @importFrom graphics grconvertX
#' @importFrom graphics grconvertY
#' @importFrom graphics legend
#' @importFrom graphics lines
#' @importFrom graphics mtext
#' @importFrom graphics par
#' @importFrom graphics points
#' @importFrom graphics segments
#' @importFrom graphics title
#' @importFrom stats predict
#' @importFrom stats quantile
#' @importFrom grDevices colorRampPalette
#' @author Robert M. Hirsch \email{rhirsch@@usgs.gov}, Laura De Cicco \email{ldecicco@@usgs.gov}
#' @references Hirsch, R.M., and De Cicco, L.A., 2014, User guide to Exploration and Graphics for RivEr Trends
#' (EGRET) and dataRetrieval: R packages for hydrologic data: U.S. Geological Survey Techniques and Methods book 4,
#' chap. A10, 94 p., \doi{10.3133/tm4A10}
#' @keywords water-quality graphics streamflow statistics
NULL
#' @keywords internal
"_PACKAGE"

#' Example eList
#'
Expand Down
2 changes: 1 addition & 1 deletion R/boxConcMonth.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ boxConcMonth <- function(eList, printTitle = TRUE,
units = localINFO$param.units)
yTicksLab <- prettyNum(yInfo$ticks)

boxplot(tempDF$conc ~ tempDF$month,
graphics::boxplot(tempDF$conc ~ tempDF$month,
ylim = c(yInfo$bottom,yInfo$top),
yaxs = "i",
yTicks = yInfo$ticks,
Expand Down
4 changes: 2 additions & 2 deletions R/boxConcThree.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE,
yTicks <- yPretty(yMax)
yTop <- yTicks[length(yTicks)]

boxplot(concV ~ index,varwidth=TRUE,
graphics::boxplot(concV ~ index,varwidth=TRUE,
names = groupNames,xlab = "", ylab = yLab,
ylim = c(0,yTop), axes = FALSE,
main = plotTitle, font.main = font.main, cex = cex,
Expand All @@ -119,7 +119,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE,
axis(2,tcl=0.5,las=1,at=yTicks,cex.axis=cex.axis)
axis(3,tcl=0.5,at=c(1,2,3),labels=FALSE)
axis(4,tcl=0.5,at=yTicks,labels=FALSE)
box()
graphics::box()
if (!tinyPlot) mtext(title2,side=3,line=-1.5)
invisible(eList)
}
2 changes: 1 addition & 1 deletion R/boxQTwice.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ boxQTwice<-function(eList,
logScaleText <- ""
}

boxplot(bigQ~index,varwidth=TRUE,
graphics::boxplot(bigQ~index,varwidth=TRUE,
names=groupNames,xlab="",
ylim=c(yInfo$bottom,yInfo$top),
main=plotTitle,cex=cex,ylab=yLabel,
Expand Down
4 changes: 2 additions & 2 deletions R/boxResidMonth.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ boxResidMonth <- function(eList,
monthList <- singleMonthList[localSample$Month]
monthList <- factor(monthList, namesListFactor)

boxplot(resid ~ monthList,
graphics::boxplot(resid ~ monthList,
varwidth = TRUE,
xlab = "Month", ylab = yLab,
main = plotTitle,
Expand All @@ -114,7 +114,7 @@ boxResidMonth <- function(eList,
cex.axis = cex.axis,
las = las,
...)
abline(h = 0)
graphics::abline(h = 0)
if (!tinyPlot) mtext(title2, side = 3, line = -1.5)
invisible(eList)
}
20 changes: 10 additions & 10 deletions R/calculateMonthlyResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ calculateMonthlyResults <- function(eList){

localDaily <- getDaily(eList)

nDays <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x
nDays <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x

Q <- aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x
DecYear <- aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x
Q <- stats::aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x
DecYear <- stats::aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x
Year <- trunc(DecYear)
Month <- aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x
Conc <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x
Flux <- aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x
FNConc <- aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x
FNFlux <- aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x
Month <- stats::aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x
Conc <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x
Flux <- stats::aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x
FNConc <- stats::aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x
FNFlux <- stats::aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x

kalman <- all(c("GenConc","GenFlux") %in% names(localDaily))

if(kalman){
GenConc <- aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x
GenFlux <- aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x
GenConc <- stats::aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x
GenFlux <- stats::aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x

MonthlyResults <- data.frame(Month, Year, nDays,
DecYear, Q,
Expand Down
4 changes: 2 additions & 2 deletions R/cumQdate.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' annualFlow <- cumQdate(eList)
#' head(annualFlow)
#' plot(annualFlow)
#' mod1 <- lm(annualFlow[,2] ~ annualFlow[,1])
#' mod1 <- stats::lm(annualFlow[,2] ~ annualFlow[,1])
#' summary(mod1)
cumQdate <- function(eList,
paStart = 10, paLong = 12,
Expand Down Expand Up @@ -65,6 +65,6 @@ cumQdate <- function(eList,
}
}

annualSeries <- na.omit(annualSeries)
annualSeries <- stats::na.omit(annualSeries)
return(annualSeries)
}
2 changes: 1 addition & 1 deletion R/estSurfaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ estSurfaces<-function(eList, surfaceStart=NA, surfaceEnd=NA, localSample=NA,

sliceIndex <- which(vectorYear >= decimalDate(as.Date(surfaceStart)) & vectorYear <=
decimalDate(as.Date(surfaceEnd)))
Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, tail(sliceIndex, n = 1)+1)]
Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, utils::tail(sliceIndex, n = 1)+1)]

nVectorYear <- length(Year)
estPtYear <- rep(Year,each=14)
Expand Down
6 changes: 3 additions & 3 deletions R/genericEGRETplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ genericEGRETDotPlot <- function(x,y, xlim, ylim,
ylim=ylim,yaxs=yaxs,ylab=if(showYLabels) ylab else "", main=plotTitle,col=col,lwd=lwd,
pch=pch,cex=cex,cex.main=cex.main,font.main=font.main,cex.lab=cex.lab,...)

box()
if (hLine) abline(h = 0)
if (oneToOneLine) abline(a=0,b=1)
graphics::box()
if (hLine) graphics::abline(h = 0)
if (oneToOneLine) graphics::abline(a=0,b=1)

if(rmSciX){
xTicksLab <- prettyNum(xTicks)
Expand Down
4 changes: 2 additions & 2 deletions R/kalman_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ WRTDSKalman <- function(eList, rho = 0.90, niter = 200,
endFill <- zends[iGap]+1
nFill <- zz$length[iGap]+2
if(i == 1 | i == numGap) {
z <- rnorm(nFill - 2)
z <- stats::rnorm(nFill - 2)
xfill <- c(xxP[startFill], z, xxP[endFill])
} else {
xfill <- genmissing(xxP[startFill], xxP[endFill], rho, nFill)
Expand Down Expand Up @@ -385,7 +385,7 @@ plotWRTDSKalman <- function(eList, sideBySide = FALSE,
ylab = ylab,
cex.main = 0.9,
plotTitle = title2)
abline(a = 0, b = 1)
graphics::abline(a = 0, b = 1)

if(sideBySide){
mtext(mainTitle, line = -1, side = 3, outer = TRUE, cex= 1)
Expand Down
8 changes: 4 additions & 4 deletions R/makeAnnualSeries.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) {
if (goodDay > 26 * paLong) {
annualSeries[1, 4:8, i] <- mean(yearDaily$DecYear,
na.rm = TRUE)
annualSeries[2, 4, i] <- median(yearDaily$Q, na.rm = TRUE)
annualSeries[2, 4, i] <- stats::median(yearDaily$Q, na.rm = TRUE)
annualSeries[2, 5, i] <- mean(yearDaily$Q, na.rm = TRUE)
annualSeries[2, 6, i] <- max(yearDaily$Q30, na.rm = TRUE)
annualSeries[2, 7, i] <- max(yearDaily$Q7, na.rm = TRUE)
Expand All @@ -111,7 +111,7 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) {
numYears <- length(x)
xVec <- seq(1,numYears)
xy <- data.frame(x,y,xVec)
xy <- na.omit(xy)
xy <- stats::na.omit(xy)
goodYears <- length(xy$x)
x <- xy$x
x1 <- x[1]
Expand All @@ -126,9 +126,9 @@ makeAnnualSeries<-function(eList, edgeAdjust = TRUE) {
window
}
w <- triCube(x - xi, thisWindow)
mod <- lm(xy$y ~ x, weights = w)
mod <- stats::lm(xy$y ~ x, weights = w)
new <- data.frame(x = x[i])
z <- exp(predict(mod, new))
z <- exp(stats::predict(mod, new))
iYear <- xy$xVec[i]
annualSeries[3, istat, iYear] <- z
}
Expand Down
2 changes: 1 addition & 1 deletion R/plot1of15.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ plot1of15<-function(eList, yearStart, yearEnd, qf, istat,
axis(2,tcl=0.5,at=yTicks,labels=FALSE)
axis(3,tcl=0.5,at=xTicks,labels=FALSE)
axis(4,tcl=0.5,at=yTicks,labels=FALSE)
box()
graphics::box()
}
6 changes: 3 additions & 3 deletions R/plotConcQSmooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,18 @@ plotConcQSmooth<-function(eList,
cols<-colorVal[index]

legendLeft <- if(legendLeft == 0) {
grconvertX(0.05, from="npc", to="user")
graphics::grconvertX(0.05, from="npc", to="user")
} else {
legendLeft
}

legendTop <- if(legendTop == 0) {
grconvertY(0.3, from="npc", to="user")
graphics::grconvertY(0.3, from="npc", to="user")
} else {
legendTop
}

if (printLegend) legend(legendLeft,legendTop ,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend)
if (printLegend) graphics::legend(legendLeft,legendTop ,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend)

printResults<-rep(NA,48*4)
dim(printResults)<-c(48,4)
Expand Down
6 changes: 3 additions & 3 deletions R/plotConcTimeSmooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ plotConcTimeSmooth<-function (eList, q1, q2, q3,
cols <- colorVal[index]

legendLeft <- if(legendLeft == 0) {
grconvertX(0.05, from="npc", to="user")
graphics::grconvertX(0.05, from="npc", to="user")
} else {
legendLeft
}

if(legendTop == 0) {
legendTop <- grconvertY(0.3, from="npc", to="user")
legendTop <- graphics::grconvertY(0.3, from="npc", to="user")
}

if (printLegend) legend(legendLeft,legendTop,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend)
if (printLegend) graphics::legend(legendLeft,legendTop,legend=words,lty=ltys,col=cols,lwd=lwd,cex=cex.legend)

printResults <- rep(NA, numX * 4)
dim(printResults) <- c(numX, 4)
Expand Down
24 changes: 12 additions & 12 deletions R/plotContours.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#' contourLevels = clevel)
#' plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50,
#' contourLevels = clevel, flowDuration = FALSE)
#' colors <- colorRampPalette(c("white","black"))
#' colors <- grDevices::colorRampPalette(c("white","black"))
#' plotContours(eList, yearStart, yearEnd, qBottom, qTop = 50,
#' contourLevels = clevel, color.palette = colors,
#' flowDuration = FALSE)
Expand All @@ -75,7 +75,7 @@ plotContours <- function(eList, yearStart, yearEnd,
yTicks = NA, tick.lwd = 1, usgsStyle = FALSE,
lwd = 2, cex.main = 1, cex.axis = 1,
concLab = 1,
color.palette = colorRampPalette(c("white","gray","blue","red")), ...) {
color.palette = grDevices::colorRampPalette(c("white","gray","blue","red")), ...) {

localINFO <- getInfo(eList)
localDaily <- getDaily(eList)
Expand Down Expand Up @@ -129,9 +129,9 @@ plotContours <- function(eList, yearStart, yearEnd,
numX<-length(x)
numY<-length(y)

qBottomT <- ifelse(is.na(qBottom), quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom)
qBottomT <- ifelse(is.na(qBottom), stats::quantile(localDaily$Q, probs = 0.05)*qFactor, qBottom)

qTopT <- ifelse(is.na(qTop), quantile(localDaily$Q, probs = 0.95)*qFactor, qTop)
qTopT <- ifelse(is.na(qTop), stats::quantile(localDaily$Q, probs = 0.95)*qFactor, qTop)

if(any(is.na(yTicks))){

Expand Down Expand Up @@ -212,28 +212,28 @@ plotContours <- function(eList, yearStart, yearEnd,
yLab<-ifelse(usgsStyle,qUnit@unitUSGS,qUnit@qUnitExpress)

logY <- log(y,10)
filled.contour(x,log(y,10),surft,levels=contourLevels,xlim=c(yearStart,yearEnd),
graphics::filled.contour(x,log(y,10),surft,levels=contourLevels,xlim=c(yearStart,yearEnd),
ylim=c(log(yTicks[1],10),log(yTicks[nYTicks],10)),
xaxs="i",yaxs="i",
color.palette=color.palette, # ...,
plot.axes={

width <- grconvertX(par("usr")[2],from="user",to="inches") - grconvertX(par("usr")[1],from="user",to="inches")
height <- grconvertY(par("usr")[4],from="user",to="inches") - grconvertY(par("usr")[3],from="user",to="inches")
width <- graphics::grconvertX(par("usr")[2],from="user",to="inches") - graphics::grconvertX(par("usr")[1],from="user",to="inches")
height <- graphics::grconvertY(par("usr")[4],from="user",to="inches") - graphics::grconvertY(par("usr")[3],from="user",to="inches")

axis(1,tcl=0,at=xTicks,labels=xlabels,cex.axis=cex.axis)
axis(2,tcl=0,las=1,at=log(yTicks,10),labels=yTicks,cex.axis=cex.axis)
axis(3, tcl = 0, at = xTicks, labels =FALSE,cex.axis=cex.axis)
axis(4, tcl = 0, at = log(yTicks, 10), labels=FALSE,cex.axis=cex.axis)
if(flowDuration) contour(x,log(y,10),durSurf,add=TRUE,drawlabels=FALSE,levels=plevels,lwd=lwd)
if(flowDuration) graphics::contour(x,log(y,10),durSurf,add=TRUE,drawlabels=FALSE,levels=plevels,lwd=lwd)
segments(v1[1],v1[2],v1[3],v1[4])
segments(v2[1],v2[2],v2[3],v2[4])
segments(h1[1],h1[2],h1[3],h1[4])

segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd)
segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(grconvertY(grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd)
segments(rep(yearStart,length(yTicks)), log(yTicks,10), rep(grconvertX(grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd)
segments(rep(grconvertX(grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(yearEnd,length(yTicks)),log(yTicks,10), lwd = tick.lwd)
segments(xTicks, rep(log(yTicks[1],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[3],from="user",to="inches")+tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd)
segments(xTicks, rep(log(yTicks[nYTicks],10),length(xTicks)), xTicks, rep(graphics::grconvertY(graphics::grconvertY(par("usr")[4],from="user",to="inches")-tcl,from="inches",to="user"),length(xTicks)), lwd = tick.lwd)
segments(rep(yearStart,length(yTicks)), log(yTicks,10), rep(graphics::grconvertX(graphics::grconvertX(par("usr")[1],from="user",to="inches")+tcl,from="inches",to="user"),length(yTicks)),log(yTicks,10), lwd = tick.lwd)
segments(rep(graphics::grconvertX(graphics::grconvertX(par("usr")[2],from="user",to="inches")-tcl,from="inches",to="user"),length(yTicks)), log(yTicks,10), rep(yearEnd,length(yTicks)),log(yTicks,10), lwd = tick.lwd)
},
plot.title = {
if(printTitle) {
Expand Down
Loading

0 comments on commit a680da8

Please sign in to comment.