header_tag.html

Skip to contents

Reads peak flow from NWISweb. Data is retrieved from https://waterdata.usgs.gov/nwis. In some cases, the specific date of the peak data is not know. This function will default to converting complete dates to a "Date" object, and converting incomplete dates to "NA". If those incomplete dates are needed, set the `asDateTime` argument to FALSE. No dates will be converted to R Date objects.

Usage

readNWISpeak(
  siteNumbers,
  startDate = "",
  endDate = "",
  asDateTime = TRUE,
  convertType = TRUE
)

Arguments

siteNumbers

character USGS site number(or multiple sites). This is usually an 8 digit number.

startDate

character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the earliest possible record.

endDate

character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record.

asDateTime

logical default to TRUE. When TRUE, the peak_dt column is converted to a Date object, and incomplete dates are removed. When FALSE, no columns are removed, but no dates are converted.

convertType

logical, defaults to TRUE. If TRUE, the function will convert the data to dates, datetimes, numerics based on a standard algorithm. If false, everything is returned as a character

Value

A data frame with the following columns:

NameTypeDescription
agency_cdcharacterThe NWIS code for the agency reporting the data
site_nocharacterThe USGS site number
peak_dtDateDate of peak streamflow
peak_tmcharacterTime of peak streamflow as character
peak_vanumericAnnual peak streamflow value in cfs
peak_cdcharacterPeak Discharge-Qualification codes (see comment for more information)
gage_htnumericGage height for the associated peak streamflow in feet
gage_ht_cdcharacterGage height qualification codes
year_last_pknumericPeak streamflow reported is the highest since this year
ag_dtDateDate of maximum gage-height for water year (if not concurrent with peak)
ag_tmcharacterTime of maximum gage-height for water year (if not concurrent with peak)
ag_gage_htnumericmaximum Gage height for water year in feet (if not concurrent with peak)
ag_gage_ht_cdcharactermaximum Gage height code

There are also several useful attributes attached to the data frame:

NameTypeDescription
urlcharacterThe url used to generate the data
queryTimePOSIXctThe time the data was returned
commentcharacterHeader comments from the RDB file
siteInfodata.frameA data frame containing information on the requested sites

Examples

site_ids <- c("01594440", "040851325")
# \donttest{
data <- readNWISpeak(site_ids)
#> GET: https://nwis.waterdata.usgs.gov/usa/nwis/peak/?site_no=01594440,040851325&range_selection=date_range&format=rdb
data2 <- readNWISpeak(site_ids, asDateTime = FALSE)
#> GET: https://nwis.waterdata.usgs.gov/usa/nwis/peak/?site_no=01594440,040851325&range_selection=date_range&format=rdb
stations <- c("06011000")
peakdata <- readNWISpeak(stations, convertType = FALSE)
#> GET: https://nwis.waterdata.usgs.gov/usa/nwis/peak/?site_no=06011000&range_selection=date_range&format=rdb
# }