# NOT RUN {
# The dataRetrieval package is not required by MGBT algorithms, but needed
# for the the plotPeaks_batch() function.
sites <- c("07358570", "07358280", "07058980", "07258000")
PK <- plotPeaks_batch(sites, xlab="WATER YEAR", lot=0,
ylab="STREAMFLOW, IN CFS", file=NA) #
# }
# NOT RUN {
# }
# NOT RUN {
# In this example, two calls to plotPeaks_batch() are made. The first is to use
# the function as a means to cache the retrieval of the peaks without the
# plotting overhead etc. The second is to actually perform the plotting.
pdffile <- tempfile(pattern = "peaks", tmpdir = tempdir(), fileext = ".pdf")
sites <- c("08106300", "08106310", "08106350", "08106500") # 08106350 no peaks
PK <- plotPeaks_batch(sites, do_plot=FALSE) # a hack to use its wrapper on
# dataRetrieval::readNWISpeak() to get the peaks retrieved and code parsed by
# splitPeakCodes() and then we can save the PK for later purposes as needed.
empty_sites <- attr(PK, "empty_sites") # we harvest 08106350 as empty
message("EMPTY SITES: ", paste(empty_sites, collapse=", "))
PK <- as.environment(PK) # now flipping to environment for the actually plotting
# plotting pass to follow next and retrieval is not made
# save(empty_sites, PK, file="PEAKS.RData") # a way to save the work for later
PK <- plotPeaks_batch(sites, xlab="WATER YEAR", lot=0, envir=PK,
ylab="STREAMFLOW, IN CFS", file=pdffile)
message("Peaks plotted in file=", pdffile) #
# }
Run the code above in your browser using DataLab