Data Retrieval
Data Retrieval
BugReports https://github.com/DOI-USGS/dataRetrieval/issues
RoxygenNote 7.3.2
NeedsCompilation no
Author Laura DeCicco [aut, cre] (ORCID:
<https://orcid.org/0000-0002-3915-9487>),
Robert Hirsch [aut] (ORCID: <https://orcid.org/0000-0002-4534-075X>),
David Lorenz [aut],
Jordan Read [ctb],
Jordan Walker [ctb],
Lindsay Platt [ctb],
David Watkins [aut] (ORCID: <https://orcid.org/0000-0002-7544-0700>),
David Blodgett [aut] (ORCID: <https://orcid.org/0000-0001-9489-1710>),
1
2 Contents
Contents
addWaterYear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
calcWaterYear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
checkWQPdates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
check_waterdata_sample_params . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
constructNWISURL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
constructUseURL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
constructWQPURL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
countyCd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
countyCdLookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
create_NWIS_bib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
create_WQP_bib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
findNLDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
getQuerySummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
getWebServiceData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
get_nldi_sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
importNGWMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
importRDB1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
importWaterML1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
importWaterML2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
importWQP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
is_dataRetrieval_user . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
parameterCdFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
parse_WQP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
pcode_to_name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
readNGWMNdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
readNGWMNlevels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
readNGWMNsites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
readNWISdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
readNWISdv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
readNWISgwl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
readNWISmeas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
readNWISpCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
readNWISpeak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
readNWISrating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
readNWISsite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
addWaterYear 3
readNWISstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
readNWISuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
readNWISuv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
readWQPdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
readWQPqw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
readWQPsummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
read_waterdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
read_waterdata_daily . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
read_waterdata_latest_continuous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
read_waterdata_metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
read_waterdata_monitoring_location . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
read_waterdata_parameter_codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
read_waterdata_samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
read_waterdata_ts_meta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
renameNWISColumns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
setAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
stateCd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
stateCdLookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
summarize_waterdata_samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
whatNWISdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
whatNWISsites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
whatWQPdata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
whatWQPsamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
wqp_check_status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
zeroPad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Index 94
Description
Add a column to the dataRetrieval data frame with the water year. WQP queries will return a water
year column for the start and end dates of the data.
Usage
addWaterYear(rawData)
Arguments
rawData the daily- or unit-values datset retrieved from NWISweb. Must have at least
one of the following columns to add the new water year columns: dateTime,
Date, ActivityStartDate, or ActivityEndDate. The date column(s) can be
character, POSIXct, Date. They cannot be numeric.
4 calcWaterYear
Value
data.frame with an additional integer column with "WY" appended to the date column name. For
WQP, there will be 2 columns: ActivityStartDateWY and ActivityEndDateWY.
Examples
nwisData <- readNWISdv("04085427", "00060", "2022-01-01", "2022-06-30")
nwisData <- addWaterYear(nwisData)
Description
Determine the correct water year based on a calendar date.
Usage
calcWaterYear(dateVec)
Arguments
dateVec vector of dates as character ("YYYY-DD-MM"), Date, or POSIXct. Numeric
does not work.
Details
This function calculates a water year based on the USGS definition that a water year starts on
October 1 of the year before, and ends on September 30. For example, water year 2015 started on
2014-10-01 and ended on 2015-09-30.
Value
numeric vector indicating the water year
Examples
x <- seq(as.Date("2010-01-01"), as.Date("2010-12-31"), by = "month")
calcWaterYear(x)
Description
Checks date format for inputs to the Water Quality Portal. Used in readWQPqw and readWQPdata.
Usage
checkWQPdates(values)
Arguments
values named list with arguments to send to the Water Quality Portal
Value
values named list with corrected arguments to send to the Water Quality Portal
Examples
values <- list(
startDateLo = "01-01-2002",
characteristicName = "Phosphorous",
endDate = as.Date("2014-01-01")
)
values <- checkWQPdates(values)
check_waterdata_sample_params
Check values from codeservice
Description
Call a service to check on values from: https://api.waterdata.usgs.gov/samples-data/
codeservice/docs.
Usage
check_waterdata_sample_params(service = "characteristicgroup", ...)
Arguments
service Options are: "characteristicgroup", "states", "counties", "countries", "sitetype",
"samplemedia", "characteristics", "observedproperty"
... Optional additional query arguments. Only "characteristics" and "observedprop-
erty" have additional parameters options.
6 constructNWISURL
Value
Examples
Description
Usage
constructNWISURL(
siteNumbers,
parameterCd = "00060",
startDate = "",
endDate = "",
service,
statCd = "00003",
format = "xml",
expanded = TRUE,
ratingType = "base",
statReportType = "daily",
statType = "mean"
)
constructNWISURL 7
Arguments
siteNumbers string or vector of strings USGS site number. This is usually an 8 digit number
parameterCd string or vector of USGS parameter code. This is usually an 5 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.
service string USGS service to call. Possible values are "dv" (daily values), "uv" (unit/instantaneous
values), "gwlevels" (groundwater),and "rating" (rating curve), "peak", "meas"
(discrete streamflow measurements), "stat" (statistics web service BETA).
statCd string or vector USGS statistic code only used for daily value service. This is
usually 5 digits. Daily mean (00003) is the default.
format string, can be "tsv" or "xml", and is only applicable for daily and unit value
requests. "tsv" returns results faster, but there is a possibility that an incomplete
file is returned without warning. XML is slower, but will offer a warning if
the file was incomplete (for example, if there was a momentary problem with
the internet connection). It is possible to safely use the "tsv" option, but the
user must carefully check the results to see if the data returns matches what is
expected. The default is therefore "xml".
expanded logical defaults to TRUE. If TRUE, retrieves additional information, only applica-
ble for qw data.
ratingType can be "base", "corr", or "exsa". Only applies to rating curve data.
statReportType character Only used for statistics service requests. Time division for statistics:
daily, monthly, or annual. Default is daily. Note that daily provides statistics
for each calendar day over the specified range of water years, i.e. no more than
366 data points will be returned for each site/parameter. Use readNWISdata or
readNWISdv for daily averages. Also note that "annual" returns statistics for the
calendar year. Use readNWISdata for water years. Monthly and yearly provide
statistics for each month and year within the range individually.
statType character Only used for statistics service requests. Type(s) of statistics to out-
put for daily values. Default is mean, which is the only option for monthly
and yearly report types. See the statistics service documentation at https:
//waterservices.usgs.gov/docs/statistics/ for a full list of codes.
Value
url string
Examples
site_id <- "01594440"
startDate <- "1985-01-01"
endDate <- ""
pCode <- c("00060", "00010")
url_daily <- constructNWISURL(site_id, pCode,
startDate, endDate, "dv",
8 constructUseURL
Description
Reconstructs URLs to retrieve data from here: https://waterdata.usgs.gov/nwis/wu
Usage
constructUseURL(years, stateCd, countyCd, categories)
Arguments
years integer Years for data retrieval. Must be years ending in 0 or 5, or "ALL", which
retrieves all available years.
stateCd could be character (full name, abbreviation, id), or numeric (id)
countyCd could be numeric (County IDs from countyCdLookup) or character ("ALL")
categories character Two-letter cateogory abbreviation(s)
Value
url string
Examples
url <- constructUseURL(
years = c(1990, 1995),
stateCd = "Ohio",
countyCd = c(1, 3),
categories = "ALL"
)
constructWQPURL 9
Description
Construct WQP url for data retrieval. This function gets the data from here: https://www.
waterqualitydata.us
Usage
constructWQPURL(siteNumbers, parameterCd, startDate, endDate, legacy = TRUE)
Arguments
siteNumbers string or vector of strings USGS site number.
parameterCd string or vector of USGS parameter code. This is usually an 5 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.
legacy Logical. If TRUE, uses legacy WQP services. Default is TRUE. Setting legacy
= FALSE uses WQX3.0 WQP services, which are in-development, use with
caution.
Value
url string
Examples
site_ids <- c("USGS-02292010", "USGS-02276877")
startDate <- "2020-01-01"
endDate <- ""
pCode <- c("80154", "00613")
url_wqp <- constructWQPURL(
site_ids,
pCode,
startDate, endDate
)
url_wqp
charNames <- c(
"Temperature",
"Temperature, sample",
"Temperature, water",
"Temperature, water, deg F"
)
obs_url_orig <- constructWQPURL(
siteNumbers = c(
10 countyCdLookup
"IIDFG-41WSSPAHS",
"USGS-02352560"
),
parameterCd = charNames,
startDate, ""
)
obs_url_orig
Description
Classic lookup table for counties. Has been replaced in functions with check_waterdata_sample_params("counties").
Value
countyCd data frame.
Examples
head(countyCd)
Description
Function to simplify finding county and county code definitions. Used in readNWISdata and
readNWISuse. Currently only has US counties.
Usage
countyCdLookup(state, county, outputType = "fips")
Arguments
state could be character (full name, abbreviation, id), or numeric (id)
county could be character (name, with or without "County") or numeric (id)
outputType character can be "fullName", "tableIndex", "id", or "fullEntry".
create_NWIS_bib 11
Examples
Description
Uses attributes from the NWIS functions to create data citations.
Usage
create_NWIS_bib(x)
Arguments
x Any data returned from an NWIS function, must include "queryTime" and "url"
attributes, which should come with the data by default.
Details
See ?bibentry for more information.
Value
bibentry object to use for citing the data.
Examples
nwisData <- readNWISdv("04085427", "00060", "2012-01-01", "2012-06-30")
nwis_citation <- create_NWIS_bib(nwisData)
nwis_citation
Description
Usage
create_WQP_bib(x)
Arguments
x Any data returned from an NWIS function, must include "queryTime" and "url"
attributes, which should come with the data by default.
Details
Value
Examples
WQPData <- readWQPqw("USGS-05288705",
parameterCd = "00300")
wqp_citation <- create_WQP_bib(WQPData)
wqp_citation
Description
Usage
findNLDI(
comid = NULL,
nwis = NULL,
wqp = NULL,
huc12 = NULL,
location = NULL,
origin = NULL,
nav = NULL,
find = c("flowlines"),
distance_km = 100,
no_sf = FALSE,
warn = TRUE
)
Arguments
comid numeric or character. An NHDPlusV2 COMID
nwis numeric or character. A USGS NWIS surface water siteID
wqp numeric or character. A water quality point ID
huc12 numeric or character. A WBD HUC12 unit ID
location numeric vector. Coordinate pair in WGS84 SRS ordered lng/lat (X,Y)
origin named list. Specifying a feature type and ID (e.g. list("comid" = 101))
nav character vector. where to navigate from the starting point. Options include
along the upper mainsteam (UM), upstream tributary (UT), downstream main-
stem (DM) and downstream divergences (DD). You may select one or more of
the abbreviations ("UM", "UT", DM", "DD").
find character vector. Define what resources to find along the navigation path(s) (see
get_nldi_sources()$source). Can also include ’basin’ or ’flowline’, which will
return the upstream basin of the starting feature or flowlines along the navigation
respectively. The default is "flowlines". If you provide any other resource, AND
want flowlines, then flowlines must be explicitly requested.
distance_km numeric. Define how far to look along the navigation path in kilometers (default
= 100)
no_sf if available, should sf be used for parsing, defaults to TRUE if sf is locally
installed
warn (default TRUE) should warnings be printed
Details
The function is useful for topology and location based feature discovery. A user must specify an
origin feature, optional navigation direction(s) along the network, as well as features to identify
along the navigated paths. Valid starting options can be given by one of the following arguments:
comid, nwis, huc12, wqp, location, and start.
14 getQuerySummary
Value
a list of data.frames if sf is not installed, a list of sf objects if it is
Examples
# MULTI-REQUEST
# UPPER MAINSTEM and TRIBUTARY of USGS-11120000
findNLDI(nwis = "11120000", nav = c("UT", "UM"))
# Control Distance
## Limit search to 50 km
findNLDI(comid = 101, nav = "DM", find = c("nwis", "flowlines"), distance_km = 50)
Description
getting header information from a WQP query
getWebServiceData 15
Usage
getQuerySummary(url)
Arguments
url the query url
Description
This function accepts a url parameter, and returns the raw data.
Usage
getWebServiceData(obs_url, ...)
Arguments
obs_url character containing the url for the retrieval
... information to pass to header request
Details
To add a custom user agent, create an environmental variable: CUSTOM_DR_UA
Value
Returns xml, json, or text depending on the requested data.
Examples
siteNumber <- "02177000"
startDate <- "2012-09-01"
endDate <- "2012-10-01"
offering <- "00003"
property <- "00060"
obs_url <- constructNWISURL(siteNumber, property, startDate, endDate, "dv")
Description
Usage
get_nldi_sources(url = pkg.env$nldi_base)
Arguments
Value
data.frame
Examples
get_nldi_sources()
importNGWMN Function to return data from the National Ground Water Monitoring
Network waterML2 format
Description
This function accepts a url parameter for a WaterML2 getObservation. This function is still under
development, but the general functionality is correct.
Usage
Arguments
input character or raw, containing the url for the retrieval or a path to the data file, or
raw XML.
asDateTime logical, if TRUE returns date and time as POSIXct, if FALSE, character
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided time zone offset. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica", "America/Managua", "Amer-
ica/Phoenix", and "America/Metlakatla". See also OlsonNames() for more in-
formation on time zones.
Value
mergedDF a data frame source, time, value, uom, uomTitle, comment, gmlID
Examples
importRDB1 Function to return data from the NWIS RDB 1.0 format
Description
This function accepts a url parameter that already contains the desired NWIS site, parameter code,
statistic, startdate and enddate. It is not recommended to use the RDB format for importing multi-
site data.
18 importRDB1
Usage
importRDB1(obs_url, asDateTime = TRUE, convertType = TRUE, tz = "UTC")
Arguments
obs_url character containing the url for the retrieval or a file path to the data file.
asDateTime logical, if TRUE returns date and time as POSIXct, if FALSE, Date
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 re-
turned as a character
tz character to set timezone attribute of datetime. Default converts the datetimes
to UTC (properly accounting for daylight savings times based on the data’s
provided tz_cd column). Recommended US values include "UTC", "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", "America/Honolulu", "America/Jamaica", "America/Managua",
"America/Phoenix", and "America/Metlakatla". For a complete list, see https:
//en.wikipedia.org/wiki/List_of_tz_database_time_zones
Value
A data frame with the following columns:
Note that code and value are repeated for the parameters requested. The names are of the form
XD_P_S, where X is literal, D is an option description of the parameter, P is the parameter code,
and S is the statistic code (if applicable). If a date/time (dt) column contained incomplete date
and times, a new column of dates and time was inserted. This could happen when older data was
reported as dates, and newer data was reported as a date/time.
There are also several useful attributes attached to the data frame:
Examples
site_id <- "02177000"
startDate <- "2012-09-01"
endDate <- "2012-10-01"
offering <- "00003"
property <- "00060"
# User file:
filePath <- system.file("extdata", package = "dataRetrieval")
fileName <- "RDB1Example.txt"
fullPath <- file.path(filePath, fileName)
importUserRDB <- importRDB1(fullPath)
Description
This function accepts a url parameter that already contains the desired NWIS site, parameter code,
statistic, startdate and enddate.
20 importWaterML1
Usage
importWaterML1(obs_url, asDateTime = FALSE, tz = "UTC")
Arguments
obs_url character or raw, containing the url for the retrieval or a file path to the data file,
or raw XML.
asDateTime logical, if TRUE returns date and time as POSIXct, if FALSE, Date
tz character to set timezone attribute of datetime. Default converts the datetimes
to UTC (properly accounting for daylight savings times based on the data’s
provided tz_cd column). Recommended US values include "UTC", "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", "America/Honolulu", "America/Jamaica", "America/Managua",
"America/Phoenix", and "America/Metlakatla". For a complete list, see https:
//en.wikipedia.org/wiki/List_of_tz_database_time_zones
Value
A data frame with the following columns:
Note that code and value are repeated for the parameters requested. The names are of the form
X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code,
and S is the statistic code (if applicable).
There are also several useful attributes attached to the data frame:
See Also
renameNWISColumns()
importWaterML1 21
Examples
# Two sites, two pcodes, one site has two data descriptors:
siteNumber <- c("01480015", "04085427")
obs_url <- constructNWISURL(
siteNumber, c("00060", "00010"),
startDate, endDate, "dv"
)
data <- importWaterML1(obs_url)
data$dateTime <- as.Date(data$dateTime)
data <- renameNWISColumns(data)
names(attributes(data))
attr(data, "url")
attr(data, "disclaimer")
Description
Returns data frame columns of all information with each time series measurement; Anything de-
fined as a default, is returned as an attribute of that data frame.
Usage
Arguments
Examples
Description
Imports data from the Water Quality Portal based on a specified url.
Usage
importWQP(obs_url, tz = "UTC", csv = TRUE, convertType = TRUE)
Arguments
obs_url character URL to Water Quality Portal#’ @keywords data import USGS web
service
tz character to set timezone attribute of datetime. Default is UTC (properly ac-
counting for daylight savings times based on the data’s provided tz_cd column).
Possible values include "America/New_York","America/Chicago", "America/Denver","America/Los_Ang
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua",
"America/Phoenix", and "America/Metlakatla"
csv logical. Is the data coming back with a csv or tsv format. Default is FALSE.
Currently, the summary service does not support tsv, for other services tsv is the
safer choice.
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 re-
turned as a character.
Value
retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime
column is supplied for start and end times, and converted to UTC. See https://www.waterqualitydata.
us/portal_userguide/ for more information.
See Also
readWQPdata(), readWQPqw(), whatWQPsites()
Examples
# These examples require an internet connection to run
Description
Reveals if this is a user or not
Usage
is_dataRetrieval_user()
Examples
is_dataRetrieval_user()
Description
Complete list of USGS parameter codes as of Oct. 24, 2024.
Value
parameterData data frame with information about USGS parameters.
Examples
head(parameterCdFile[, 1:2])
parse_WQP 25
Description
Usage
parse_WQP(retval, tz = "UTC")
Arguments
Value
Examples
Description
This function is useful to fine what characteristic name, result sample fraction, unit code, and other
parameters are mapped with USGS parameter codes. This information is useful for converting
workflows from a more traditional NWIS water quality retrieval to a Water Quality Portal retrieval.
Usage
pcode_to_name(parameterCd = "all")
Arguments
parameterCd character that contains the code for a character vector of 5-digit parameter codes.
Default is "all" which will return a complete list of parameter codes that have
been mapped to a characteristic name.
Value
a data frame with columns "parm_cd", "description", "characteristicname", "measureunitcode", "re-
sultsamplefraction", "resulttemperaturebasis", "resultstatisticalbasis", "resulttimebasis", "resultweight-
basis", "resultparticlesizebasis", "last_rev_dt"
Examples
pcodes <- c("00070", "00075", "00430", "52642")
Description
Only water level data and site locations and names are currently available through the web service.
Usage
readNGWMNdata(service, ..., asDateTime = TRUE, tz = "UTC")
readNGWMNlevels 27
Arguments
service char Service for the request - "observation" and "featureOfInterest" are imple-
mented.
... Other parameters to supply, namely siteNumbers or bbox
asDateTime logical if TRUE, will convert times to POSIXct format. Currently defaults to
FALSE since time zone information is not included.
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided time zone offset. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica", "America/Managua", "Amer-
ica/Phoenix", and "America/Metlakatla". See also OlsonNames() for more in-
formation on time zones.
Examples
# one site
site <- "USGS.430427089284901"
#oneSite <- readNGWMNdata(siteNumbers = site, service = "observation")
# multiple sites
sites <- c("USGS.272838082142201", "USGS.404159100494601", "USGS.401216080362703")
# Very slow:
# multiSiteData <- readNGWMNdata(siteNumbers = sites, service = "observation")
# attributes(multiSiteData)
# non-USGS site
# accepts colon or period between agency and ID
site <- "MBMG:702934"
# data <- readNGWMNdata(siteNumbers = site, service = "featureOfInterest")
# bounding box
# bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -102, 31, 99))
# retrieve sites. Set asDateTime to false since one site has an invalid date
# Very slow:
# bboxData <- readNGWMNdata(service = "observation", siteNumbers = bboxSites$site[1:3],
# asDateTime = FALSE)
readNGWMNlevels Retrieve groundwater levels from the National Ground Water Moni-
toring Network.
28 readNGWMNlevels
Description
Retrieve groundwater levels from the National Ground Water Monitoring Network.
Usage
Arguments
siteNumbers character Vector of feature IDs formatted with agency code and site number
separated by a period or semicolon, e.g. USGS.404159100494601.
asDateTime logical Should dates and times be converted to date/time objects, or returned as
character? Defaults to TRUE. Must be set to FALSE if a site contains non-standard
dates.
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided time zone offset. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica", "America/Managua", "Amer-
ica/Phoenix", and "America/Metlakatla". See also OlsonNames() for more in-
formation on time zones.
Examples
# one site
site <- "USGS.430427089284901"
# oneSite <- readNGWMNlevels(siteNumbers = site)
# multiple sites
sites <- c("USGS:272838082142201", "USGS:404159100494601", "USGS:401216080362703")
# multiSiteData <- readNGWMNlevels(sites)
# non-USGS site
site <- "MBMG.103306"
# data <- readNGWMNlevels(siteNumbers = site, asDateTime = FALSE)
readNGWMNsites Retrieve site data from the National Ground Water Monitoring Net-
work.
Description
Retrieve site data from the National Ground Water Monitoring Network.
Usage
readNGWMNsites(siteNumbers)
Arguments
siteNumbers character Vector of feature IDs formatted with agency code and site number
separated by a period or semicolon, e.g. USGS.404159100494601.
Value
Examples
# one site
site <- "USGS.430427089284901"
#oneSite <- readNGWMNsites(siteNumbers = site)
# non-USGS site
site <- "MBMG.103306"
#siteInfo <- readNGWMNsites(siteNumbers = site)
30 readNWISdata
Description
Returns data from the NWIS web service. Arguments to the function should be based on https:
//waterservices.usgs.gov service calls. See examples below for ideas of constructing queries.
Usage
readNWISdata(..., asDateTime = TRUE, convertType = TRUE, tz = "UTC")
Arguments
... see https://waterservices.usgs.gov/docs/site-service/ for a complete
list of options. A list of arguments can also be supplied. One important argu-
ment to include is "service". Possible values are "iv" (for instantaneous), "dv"
(for daily values), "gwlevels" (for groundwater levels), "site" (for site service),
"measurement", and "stat" (for statistics service). Note: "measurement" calls go
to: https://nwis.waterdata.usgs.gov/usa/nwis for data requests, and use
different call requests schemes. The statistics service has a limited selection of
arguments (see https://waterservices.usgs.gov/docs/site-service/).
asDateTime logical, if TRUE returns date and time as POSIXct, if FALSE, Date
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 re-
turned as a character
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided tz_cd column. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica", "America/Managua", "Amer-
ica/Phoenix", and "America/Metlakatla". See also OlsonNames() for more in-
formation on time zones.
Details
This function requires users to create their own arguments based on the NWIS web services. It
is a more complicated function to use compared to other NWIS functions such as readNWISdv(),
readNWISuv(), readNWISgwl(), etc. However, this function adds a lot of flexibility to the possible
queries. This function will also behave exactly as NWIS when it comes to date queries. NWIS
by default will only return the latest value for the daily and instantaneous services. So if you do
not provide a starting date, you will only get back the latest value. If you want the full period of
record, you can use "startDate = ’1900-01-01’". Other options for dates are periods, such as "period
= ’P7D’" which translates to a period of 7 days. For period, use only a positive ISO-8601 duration
format, which should not be expressed in periods of less than a day, or in increments of months M
readNWISdata 31
or years Y. period returns data for a site generally from now to a time in the past. Note that when
period is used all data up to the most recent value are returned.
Value
A data frame with the following columns:
Note that code and value are repeated for the parameters requested. The names are of the form
X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code,
and S is the statistic code (if applicable).
There are also several useful attributes attached to the data frame:
See Also
read_waterdata()
Examples
Description
Imports data from NWIS daily web service. This function gets the data from here: https://
waterservices.usgs.gov/docs/dv-service/daily-values-service-details/ Inputs to this
function are just USGS site ids, USGS parameter codes, USGS statistic codes, and start and end
date. For a more complex query, use readNWISdata(), with an argument service = "dv". Data
coming the daily web services are aggregates of the instantaneous (sensor) web services. Not all
statistical codes are available for all data. Use the function whatNWISdata() to discover what
data is available for a USGS site. The column data_type_cd with the values "dv" returned from
whatNWISdata()) are available from this service.
Usage
readNWISdv(
siteNumbers,
parameterCd,
startDate = "",
endDate = "",
statCd = "00003"
)
34 readNWISdv
Arguments
siteNumbers character USGS site number. This is usually an 8 digit number. Multiple sites
can be requested with a character vector.
parameterCd character of USGS parameter code(s). This is usually an 5 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. Date arguments are
always specified in local time.
endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is
"" which indicates retrieval for the latest possible record. Date arguments are
always specified in local time.
statCd character USGS statistic code. This is usually 5 digits. Daily mean (00003) is
the default.
Details
More information on the web service can be found here: https://waterservices.usgs.gov/
test-tools, choosing the "Daily Value Service".
Value
A data frame with the following columns:
Note that code and value are repeated for the parameters requested. The names are of the form
X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code,
and S is the statistic code (if applicable).
There are also several useful attributes attached to the data frame:
See Also
read_waterdata_daily()
readNWISgwl 35
Examples
# see ?read_waterdata_daily
Description
Imports groundwater level data from NWIS web service. This function gets the data from here:
https://waterservices.usgs.gov/docs/groundwater-levels/groundwater-levels-details/
Inputs to this function are just USGS site ids, USGS parameter codes, and start and end date. For
a more complex query, use readNWISdata(), including an argument service="gwlevels". Not all
parameter codes are available for all data. Use the function whatNWISdata() to discover what
data is available for a USGS site. The column data_type_cd with the values "gw" returned from
whatNWISdata()) are available from this service.
Usage
readNWISgwl(
siteNumbers,
startDate = "",
endDate = "",
parameterCd = NA,
convertType = TRUE,
tz = "UTC"
)
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.
parameterCd character USGS parameter code. This is usually an 5 digit number. Default is
"".
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 re-
turned as a character
36 readNWISgwl
Details
More information on the web service can be found here: https://waterservices.usgs.gov/
test-tools, choosing the "Groundwater Levels Value Service".
Mixed date/times come back from the service depending on the year that the data was collected.
See https://waterdata.usgs.gov/usa/nwis/gw for details about groundwater. By default the
returned dates are converted to date objects, unless convertType is specified as FALSE. Sites with
non-standard date formats (i.e. lacking a day) can be affected (see examples). See https://
waterservices.usgs.gov/docs/groundwater-levels/ for more information.
Value
A data frame with the following columns:
There are also several useful attributes attached to the data frame:
See Also
constructNWISURL(), importRDB1()
readNWISmeas 37
Examples
site_id <- "434400121275801"
Description
Reads surface-water measurement data from NWISweb. Data is retrieved from https://waterdata.
usgs.gov/nwis. See https://waterdata.usgs.gov/usa/nwis/sw for details about surface wa-
ter.
Usage
readNWISmeas(
siteNumbers,
startDate = "",
endDate = "",
tz = "UTC",
expanded = FALSE,
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.
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided tz_cd column. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
38 readNWISmeas
Value
A data frame with at least the following columns:
See Also
constructNWISURL(), importRDB1()
Examples
site_ids <- c("01594440", "040851325")
Description
Imports data from NWIS about measured parameter based on user-supplied parameter code or
codes. This function gets the data from here: https://nwis.waterdata.usgs.gov/nwis/pmcodes
Usage
readNWISpCode(parameterCd)
Arguments
parameterCd character of USGS parameter codes (or multiple parameter codes). These are 5
digit number codes. To get a complete list of all current parameter codes in the
USGS, use "all" as the input.
Value
parameterData data frame with the following information:
See Also
importRDB1()
Description
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.
40 readNWISpeak
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 re-
moved, 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 re-
turned as a character
Value
A data frame with the following columns:
There are also several useful attributes attached to the data frame:
See Also
constructNWISURL(), importRDB1()
Examples
site_ids <- c("01594440", "040851325")
Description
Reads current rating table for an active USGS streamgage from NWISweb. Data is retrieved from
https://waterdata.usgs.gov/nwis.
Usage
readNWISrating(siteNumber, type = "base", convertType = TRUE)
Arguments
siteNumber character USGS site number. This is usually an 8 digit number
type character can be "base", "corr", or "exsa"
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 re-
turned as a character
Value
A data frame. If type is "base, " then the columns are INDEP, typically the gage height, in feet;
DEP, typically the streamflow, in cubic feet per second; and STOR, where "*" indicates that the
pair are a fixed point of the rating curve. If type is "exsa, " then an additional column, SHIFT, is
included that indicates the current shift in the rating for that value of INDEP. If type is "corr, " then
the columns are INDEP, typically the gage height, in feet; CORR, the correction for that value; and
42 readNWISsite
Note
Not all active USGS streamgages have traditional rating curves that relate flow to stage.
See Also
constructNWISURL(), importRDB1()
Examples
site_id <- "01594440"
Description
Imports data from USGS site file site. This function gets data from here: https://waterservices.
usgs.gov/
Usage
readNWISsite(siteNumbers)
Arguments
siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number
readNWISsite 43
Value
There are also several useful attributes attached to the data frame:
See Also
read_waterdata_monitoring_location()
Examples
# see ?read_waterdata_monitoring_location
# siteINFOMulti <- readNWISsite(c("05114000", "09423350"))
Description
Retrieves site statistics from the USGS Statistics Web Service beta. See https://waterservices.
usgs.gov/docs/statistics/ for more information.
Usage
readNWISstat(
siteNumbers,
parameterCd,
startDate = "",
endDate = "",
convertType = TRUE,
statReportType = "daily",
statType = "mean"
)
Arguments
siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit num-
ber.
parameterCd character USGS parameter code. This is usually a 5 digit number.
startDate character starting date for data retrieval in the form YYYY, YYYY-MM, or
YYYY-MM-DD. Dates cannot be more specific than the statReportType, i.e.
startDate for monthly statReportTypes cannot include days, and annual statRe-
portTypes cannot include days or months. Months and days are optional for the
readNWISstat 45
daily statReportType. Default is "" which indicates retrieval for the earliest pos-
sible record. For daily data, this indicates the start of the period the statistics
will be computed over.
endDate character ending date for data retrieval in the form YYYY, YYYY-MM, or
YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible
record. For daily data, this indicates the end of the period the statistics will be
computed over. The same restrictions as startDate apply.
convertType logical, defaults to TRUE. If TRUE, the function will convert the data to numerics
based on a standard algorithm. Years, months, and days (if appliccable) are also
returned as numerics in separate columns. If convertType is false, everything is
returned as a character.
statReportType character time division for statistics: daily, monthly, or annual. Default is daily.
Note that daily provides statistics for each calendar day over the specified range
of water years, i.e. no more than 366 data points will be returned for each
site/parameter. Use readNWISdata or readNWISdv for daily averages. Also
note that ’annual’ returns statistics for the calendar year. Use readNWISdata
for water years. Monthly and yearly provide statistics for each month and year
within the range indivually.
statType character type(s) of statistics to output for daily values. Default is mean, which
is the only option for monthly and yearly report types. See the statistics service
documentation at https://waterservices.usgs.gov/docs/statistics/ for
a full list of codes.
Value
A data frame with the following columns:
See Also
constructNWISURL(), importRDB1()
Examples
x1 <- readNWISstat(
siteNumbers = c("02319394"),
parameterCd = c("00060"),
statReportType = "annual"
)
# Request p25, p75, and mean values for temperature and discharge for the 2000s
# Note that p25 and p75 were not available for temperature, and return NAs
x <- readNWISstat(
siteNumbers = c("02171500"),
parameterCd = c("00010", "00060"),
statReportType = "daily",
statType = c("mean", "median"),
startDate = "2000", endDate = "2010"
)
Description
Retrieves water use data from USGS Water Use Data for the Nation. See https://waterdata.
usgs.gov/nwis/wu for more information. All available use categories for the supplied arguments
are retrieved.
Usage
readNWISuse(
stateCd,
countyCd,
years = "ALL",
categories = "ALL",
convertType = TRUE,
transform = FALSE
)
Arguments
stateCd could be character (full name, abbreviation, id), or numeric (id). Only one is
accepted per query.
countyCd could be character (name, with or without "County", or "ALL"), numeric (id),
or NULL, which will return state or national data depending on the stateCd argu-
ment. "ALL" may also be supplied, which will return data for every county in a
state. Can be a vector of counties in the same state.
years integer Years for data retrieval. Must be years ending in 0 or 5. Default is all
available years.
readNWISuv 47
categories character categories of water use. Defaults to "ALL". Specific categories must
be supplied as two- letter abbreviations as seen in the URL when using the NWIS
water use web interface. Note that there are different codes for national and state
level data.
convertType logical defaults to TRUE. If TRUE, the function will convert the data to numerics
based on a standard algorithm. Years, months, and days (if appliccable) are also
returned as numerics in separate columns. If convertType is false, everything is
returned as a character.
transform logical only intended for use with national data. Defaults to FALSE, with data
being returned as presented by the web service. If TRUE, data will be transformed
and returned with column names, which will reformat national data to be similar
to state data.
Value
A data frame with at least the year of record, and all available statistics for the given geographic
parameters. County and state fields will be included as appropriate.
Examples
# All national-scale data, transforming data frame to named columns from named rows
national <- readNWISuse(stateCd = NULL, countyCd = NULL, transform = TRUE)
# Washington, DC data
dc <- readNWISuse(stateCd = "DC", countyCd = NULL)
Description
Imports data from NWIS web service. This function gets the data from here: https://waterservices.
usgs.gov/docs/instantaneous-values/instantaneous-values-details/ Inputs to this func-
tion are just USGS site ids, USGS parameter codes, and start and end date. For a more complex
query, use readNWISdata(), including an arguement service="uv". Not all parameter codes are
available for all data. Use the function whatNWISdata() to discover what data is available for a
USGS site. The column data_type_cd with the values "uv" returned from whatNWISdata()) are
available from this service.
Usage
readNWISuv(siteNumbers, parameterCd, startDate = "", endDate = "", tz = "UTC")
Arguments
siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number
parameterCd character USGS parameter code. This is usually an 5 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. Simple date
arguments are specified in local time. See more information here: https:
//waterservices.usgs.gov/docs/instantaneous-values/.
endDate character ending date for data retrieval in the form YYYY-MM-DD. Default
is "" which indicates retrieval for the latest possible record. Simple date ar-
guments are specified in local time. See more information here: https://
waterservices.usgs.gov/docs/instantaneous-values/.
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided tz_cd column. Possible values to provide are "Amer-
ica/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica", "America/Managua", "Amer-
ica/Phoenix", and "America/Metlakatla". See also OlsonNames() for more in-
formation on time zones.
Details
More information on the web service can be found here: https://waterservices.usgs.gov/
test-tools, choosing the "Instantaneous Value Service".
Value
A data frame with the following columns:
Note that code and value are repeated for the parameters requested. The names are of the form:
X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code,
and S is the statistic code (if applicable).
There are also several useful attributes attached to the data frame:
Name Type Description
url character The url used to generate the data
siteInfo data.frame A data frame containing information on the requested sites
variableInfo data.frame A data frame containing information on the requested parameters
statisticInfo data.frame A data frame containing information on the requested statistics on the data
queryTime POSIXct The time the data was returned
See Also
renameNWISColumns(), importWaterML1()
Examples
site_id <- "05114000"
parameterCd <- "00060"
startDate <- "2014-10-10"
endDate <- "2014-10-10"
# Adding 'Z' to the time indicates to the web service to call the data with UTC time:
GMTdata <- readNWISuv(
site_id, parameterCd,
"2014-10-10T00:00Z", "2014-10-10T23:59Z"
)
50 readWQPdata
Description
Imports data from Water Quality Portal web service. This function gets the data from here: https:
//www.waterqualitydata.us.
Usage
readWQPdata(
...,
service = "Result",
querySummary = FALSE,
tz = "UTC",
ignore_attributes = FALSE,
convertType = TRUE
)
Arguments
... see https://www.waterqualitydata.us/webservices_documentation for
a complete list of options. A list of arguments can also be supplied. For more in-
formation see the above description for this help file. One way to figure out how
to construct a WQP query is to go to the "Advanced" form in the Water Quality
Portal. Use the form to discover what parameters are available. Once the query
is set in the form, scroll down to the "Query URL". You will see the parameters
after "https://www.waterqualitydata.us/#". For example, if you chose "Nutrient"
in the Characteristic Group dropdown, you will see characteristicType=Nutrient
in the Query URL. The corresponding argument for dataRetrieval is characteris-
ticType = "Nutrient". dataRetrieval users do not need to include mimeType, and
providers is optional (these arguments are picked automatically).
service character. See Details for more information.
querySummary logical to only return the number of records and unique sites that will be re-
turned from this query. Choosing TRUE is deprecated, readWQPsummary is
recommended instead.
tz character to set timezone attribute of dateTime. Default is "UTC", and converts
the date times to UTC, properly accounting for daylight savings times based
on the data’s provided tz_cd column. Possible values to provide are "Amer-
ica/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
"America/Anchorage", as well as the following which do not use daylight sav-
ings time: "America/Honolulu", "America/Jamaica","America/Managua","America/Phoenix",
and "America/Metlakatla". See also OlsonNames() for more information on
time zones.
ignore_attributes
logical to choose to ignore fetching site and status attributes. Default is FALSE.
readWQPdata 51
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 re-
turned as a character.
Details
This function uses . . . as a query input, which can be very flexible, but also has a steeper learning
curve. For a quick overview, scroll down to the Examples in this help file to see many query options.
There are currently 10 legacy options for data provided by the Water Quality Portal:
Legacy:
There are 4 WQX3 options. These are still in-development, and should be used with caution.
Value
A data frame, the specific columns will depend on the "service" and/or "dataProfile".
There are also several useful attributes attached to the data frame:
Examples
# Legacy:
nameToUse <- "pH"
pHData <- readWQPdata(siteid = "USGS-04024315",
characteristicName = nameToUse)
ncol(pHData)
attr(pHData, "siteInfo")
attr(pHData, "queryTime")
attr(pHData, "url")
# WQX3:
pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315",
characteristicName = nameToUse,
service = "ResultWQX3",
dataProfile = "basicPhysChem")
attr(pHData_wqx3, "url")
# More examples:
# querying by county
DeWitt <- readWQPdata(
statecode = "Illinois",
countycode = "DeWitt",
characteristicName = "Nitrogen"
)
attr(DeWitt, "url")
attr(DeWitt_wqx3, "url")
########################################################
# Additional examples:
dataProfile = "biological",
service = "Result"
)
# other options:
Phosphorus <- readWQPdata(
statecode = "WI", countycode = "Dane",
characteristicName = "Phosphorus",
startDateLo = "2023-01-01",
ignore_attributes = TRUE,
convertType = FALSE
)
Description
Imports data from the Water Quality Portal. This function gets the data from here: https://
www.waterqualitydata.us. There are four required input arguments: siteNumbers, parameterCd,
startDate, and endDate. parameterCd can either be a USGS 5-digit code, or a characteristic name.
The sites can be either USGS, or other Water Quality Portal offered sites. It is required to use the
’full’ site name, such as ’USGS-01234567’.
Usage
readWQPqw(
siteNumbers,
parameterCd,
startDate = "",
endDate = "",
tz = "UTC",
legacy = TRUE,
querySummary = FALSE,
ignore_attributes = FALSE,
convertType = TRUE
)
Arguments
siteNumbers character site number. This needs to include the full agency code prefix.
parameterCd vector of USGS 5-digit parameter code or characteristicNames. Leaving this
blank will return all of the measured values during the specified time period.
startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is
"" which indicates retrieval for the earliest possible record. Date arguments are
always specified in local time.
endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is
"" which indicates retrieval for the latest possible record. Date arguments are
always specified in local time.
56 readWQPqw
Value
A data frame derived from the default data profile.
There are also several useful attributes attached to the data frame:
Name Type Description
url character The url used to generate the data
siteInfo data.frame A data frame containing information on the requested sites
variableInfo data.frame A data frame containing information on the requested parameters
queryTime POSIXct The time the data was returned
See Also
readWQPdata(), whatWQPsites(), and importWQP()
Examples
attr(rawPcode, "siteInfo")
attr(rawPcode, "queryTime")
attr(rawPcode, "url")
attr(pHsites_legacy, "url")
Description
Returns a list of sites with year-by-year information on what data is available. The function gets the
data from: https://www.waterqualitydata.us. Arguments to the function should be based on
https://www.waterqualitydata.us/webservices_documentation. The information returned
from this function describes the available data at the WQP sites, and some metadata on the sites
themselves.
Usage
readWQPsummary(...)
Arguments
... see https://www.waterqualitydata.us/webservices_documentation for
a complete list of options. A list of arguments can also be supplied. One way to
figure out how to construct a WQP query is to go to the "Advanced" form in the
Water Quality Portal: https://www.waterqualitydata.us/#mimeType=csv&
providers=NWIS&providers=STORET Use the form to discover what parame-
ters are available. Once the query is set in the form, scroll down to the "Query
URL". You will see the parameters after "https://www.waterqualitydata.us/#".
For example, if you chose "Nutrient" in the Characteristic Group dropdown, you
will see characteristicType=Nutrient in the Query URL. The corresponding ar-
gument for dataRetrieval is characteristicType = "Nutrient". dataRetrieval users
do not need to include mimeType, and providers is optional (these arguments
are picked automatically).
Value
A data frame from the data returned from the Water Quality Portal about the data available for the
query parameters.
58 read_waterdata
See Also
whatWQPsites whatWQPdata
Examples
# Summary of the data available for the last 5 years in New Jersey:
state1 <- readWQPsummary(
statecode = "NJ",
summaryYears = 5,
siteType = "Stream"
)
Description
Usage
read_waterdata(service, CQL, ..., convertType = TRUE)
Arguments
service character, can be any existing collection such as "daily", "monitoring-locations",
"time-series-metadata"
CQL A string in a Common Query Language format.
... Additional arguments to send to the request.
convertType logical, defaults to TRUE. If TRUE, the function will convert the data to dates and
qualifier to string vector.
Examples
# A wildcard in CQL2 is %
# Here's how to get HUCs that fall within 02070010
cql_huc_wildcard <- '{
"op": "like",
"args": [
{ "property": "hydrologic_unit_code" },
"02070010%"
]
}'
CQL = cql_huc_wildcard)
Description
Daily data provide one data value to represent water conditions for the day. Throughout much of
the history of the USGS, the primary water data available was daily data collected manually at the
monitoring location once each day. With improved availability of computer storage and automated
transmission of data, the daily data published today are generally a statistical summary or metric
of the continuous data collected each day, such as the daily mean, minimum, or maximum value.
Daily data are automatically calculated from the continuous data of the same parameter code and
are described by parameter code and a statistic code. These data have also been referred to as “daily
values” or “DV”.
Usage
read_waterdata_daily(
monitoring_location_id = NA_character_,
parameter_code = NA_character_,
statistic_id = NA_character_,
properties = NA_character_,
time_series_id = NA_character_,
daily_id = NA_character_,
approval_status = NA_character_,
unit_of_measure = NA_character_,
qualifier = NA_character_,
value = NA,
last_modified = NA_character_,
skipGeometry = NA,
time = NA_character_,
bbox = NA,
limit = NA,
max_results = NA,
convertType = TRUE
)
Arguments
monitoring_location_id
A unique identifier representing a single monitoring location. This corresponds
to the id field in the monitoring-locations endpoint. Monitoring location
IDs are created by combining the agency code of the agency responsible for the
monitoring location (e.g. USGS) with the ID number of the monitoring location
(e.g. 02238500), separated by a hyphen (e.g. USGS-02238500).
read_waterdata_daily 61
parameter_code Parameter codes are 5-digit codes used to identify the constituent measured and
the units of measure. A complete list of parameter codes and associated group-
ings can be found at https://help.waterdata.usgs.gov/codes-and-parameters/
parameters.
statistic_id A code corresponding to the statistic an observation represents. Example codes
include 00001 (max), 00002 (min), and 00003 (mean). A complete list of codes
and their descriptions can be found at https://help.waterdata.usgs.gov/
code/stat_cd_nm_query?stat_nm_cd=%25&fmt=html.
properties A vector of requested columns to be returned from the query. Available options
are: geometry, id, time_series_id, monitoring_location_id, parameter_code, statis-
tic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified
time_series_id A unique identifier representing a single time series. This corresponds to the id
field in the time-series-metadata endpoint.
daily_id A universally unique identifier (UUID) representing a single version of a record.
It is not stable over time. Every time the record is refreshed in our database
(which may happen as part of normal operations and does not imply any change
to the data itself) a new ID will be generated. To uniquely identify a single
observation over time, compare the time and time_series_id fields; each time
series will only have a single observation at a given time.
approval_status
Some of the data that you have obtained from this U.S. Geological Survey
database may not have received Director’s approval. Any such data values are
qualified as provisional and are subject to revision. Provisional data are released
on the condition that neither the USGS nor the United States Government may
be held liable for any damages resulting from its use. This field reflects the
approval status of each record, and is either "Approved", meaining processing
review has been completed and the data is approved for publication, or "Provi-
sional" and subject to revision. For more information about provisional data, go
to https://waterdata.usgs.gov/provisional-data-statement/.
unit_of_measure
A human-readable description of the units of measurement associated with an
observation.
qualifier This field indicates any qualifiers associated with an observation, for instance if
a sensor may have been impacted by ice or if values were estimated.
value The value of the observation. Values are transmitted as strings in the JSON
response format in order to preserve precision.
last_modified The last time a record was refreshed in our database. This may happen due to
regular operational processes and does not necessarily indicate anything about
the measurement has changed. You can query this field using date-times or
intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals
may be bounded or half-bounded (double-dots at start or end). Examples:
• A date-time: "2018-02-12T23:20:50Z"
• A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
• Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
• Duration objects: "P1M" for data from the past month or "PT36H" for the
last 36 hours
62 read_waterdata_daily
Only features that have a last_modified that intersects the value of datetime
are selected. If a feature has multiple temporal properties, it is the decision of the
server whether only a single temporal property is used to determine the extent
or all relevant temporal properties.
skipGeometry This option can be used to skip response geometries for each feature. The re-
turning object will be a data frame with no spatial information.
time The date an observation represents. You can query this field using date-times or
intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals
may be bounded or half-bounded (double-dots at start or end). Examples:
• A date-time: "2018-02-12T23:20:50Z"
• A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
• Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
• Duration objects: "P1M" for data from the past month or "PT36H" for the
last 36 hours
Only features that have a time that intersects the value of datetime are selected.
If a feature has multiple temporal properties, it is the decision of the server
whether only a single temporal property is used to determine the extent or all
relevant temporal properties.
bbox Only features that have a geometry that intersects the bounding box are se-
lected.The bounding box is provided as four or six numbers, depending on
whether the coordinate reference system includes a vertical axis (height or depth).
Coordinates are assumed to be in crs 4326. The expected format is a numeric
vector structured: c(xmin,ymin,xmax,ymax). Another way to think of it is
c(Western-most longitude, Southern-most latitude, Eastern-most longitude, Northern-
most longitude).
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
convertType logical, defaults to TRUE. If TRUE, the function will convert the data to dates and
qualifier to string vector.
Examples
read_waterdata_latest_continuous
Get Latest Continuous USGS Water Data
Description
This endpoint provides the most recent observation for each time series of continuous data. Contin-
uous data are collected via automated sensors installed at a monitoring location. They are collected
at a high frequency and often at a fixed 15-minute interval. Depending on the specific monitoring
location, the data may be transmitted automatically via telemetry and be available on WDFN within
minutes of collection, while other times the delivery of data may be delayed if the monitoring lo-
cation does not have the capacity to automatically transmit data. Continuous data are described by
parameter name and parameter code. These data might also be referred to as "instantaneous values"
or "IV"
Usage
read_waterdata_latest_continuous(
monitoring_location_id = NA_character_,
parameter_code = NA_character_,
statistic_id = NA_character_,
properties = NA_character_,
time_series_id = NA_character_,
latest_continuous_id = NA_character_,
64 read_waterdata_latest_continuous
approval_status = NA_character_,
unit_of_measure = NA_character_,
qualifier = NA_character_,
value = NA,
last_modified = NA_character_,
skipGeometry = NA,
time = NA_character_,
bbox = NA,
limit = NA,
max_results = NA,
convertType = TRUE
)
Arguments
monitoring_location_id
A unique identifier representing a single monitoring location. This corresponds
to the id field in the monitoring-locations endpoint. Monitoring location
IDs are created by combining the agency code of the agency responsible for the
monitoring location (e.g. USGS) with the ID number of the monitoring location
(e.g. 02238500), separated by a hyphen (e.g. USGS-02238500).
parameter_code Parameter codes are 5-digit codes used to identify the constituent measured and
the units of measure. A complete list of parameter codes and associated group-
ings can be found at https://help.waterdata.usgs.gov/codes-and-parameters/
parameters.
statistic_id A code corresponding to the statistic an observation represents. Example codes
include 00001 (max), 00002 (min), and 00003 (mean). A complete list of codes
and their descriptions can be found at https://help.waterdata.usgs.gov/
code/stat_cd_nm_query?stat_nm_cd=%25&fmt=html.
properties A vector of requested columns to be returned from the query. Available options
are: geometry, id, time_series_id, monitoring_location_id, parameter_code, statis-
tic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified
time_series_id A unique identifier representing a single time series. This corresponds to the id
field in the time-series-metadata endpoint.
latest_continuous_id
A universally unique identifier (UUID) representing a single version of a record.
It is not stable over time. Every time the record is refreshed in our database
(which may happen as part of normal operations and does not imply any change
to the data itself) a new ID will be generated. To uniquely identify a single
observation over time, compare the time and time_series_id fields; each time
series will only have a single observation at a given time.
approval_status
Some of the data that you have obtained from this U.S. Geological Survey
database may not have received Director’s approval. Any such data values are
qualified as provisional and are subject to revision. Provisional data are released
on the condition that neither the USGS nor the United States Government may
be held liable for any damages resulting from its use. This field reflects the
read_waterdata_latest_continuous 65
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
convertType logical, defaults to TRUE. If TRUE, the function will convert the data to dates and
qualifier to string vector.
Examples
read_waterdata_metadata
Generalized USGS Water Meta Data API retrieval function
read_waterdata_monitoring_location 67
Description
Function to get metadata from Water Data API. These are useful to get the human readable words
and other metadata associated with USGS codes.
Usage
read_waterdata_metadata(collection, max_results = NA, limit = NA)
Arguments
collection character, can be any existing collection such as "parameter-codes", "agency-
codes", "altitude-datums", "aquifer-codes", "aquifer-types", "coordinate-accuracy-
codes", "coordinate-datum-codes", "coordinate-method-codes", "hydrologic-unit-
codes", "medium-codes", "national-aquifer-codes", "reliability-codes", "site-types",
"statistic-codes", "topographic-codes", "time-zone-codes".
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
Examples
read_waterdata_monitoring_location
Get USGS Site Data
68 read_waterdata_monitoring_location
Description
Location information is basic information about the monitoring location including the name, iden-
tifier, agency responsible for data collection, and the date the location was established. It also
includes information about the type of location, such as stream, lake, or groundwater, and geo-
graphic information about the location, such as state, county, latitude and longitude, and hydrologic
unit code (HUC).
Usage
read_waterdata_monitoring_location(
monitoring_location_id = NA_character_,
agency_code = NA_character_,
agency_name = NA_character_,
monitoring_location_number = NA_character_,
monitoring_location_name = NA_character_,
district_code = NA_character_,
country_code = NA_character_,
country_name = NA_character_,
state_code = NA_character_,
state_name = NA_character_,
county_code = NA_character_,
county_name = NA_character_,
minor_civil_division_code = NA_character_,
site_type_code = NA_character_,
site_type = NA_character_,
hydrologic_unit_code = NA_character_,
basin_code = NA_character_,
altitude = NA_character_,
altitude_accuracy = NA_character_,
altitude_method_code = NA_character_,
altitude_method_name = NA_character_,
vertical_datum = NA_character_,
vertical_datum_name = NA_character_,
horizontal_positional_accuracy_code = NA_character_,
horizontal_positional_accuracy = NA_character_,
horizontal_position_method_code = NA_character_,
horizontal_position_method_name = NA_character_,
original_horizontal_datum = NA_character_,
original_horizontal_datum_name = NA_character_,
drainage_area = NA_character_,
contributing_drainage_area = NA_character_,
time_zone_abbreviation = NA_character_,
uses_daylight_savings = NA_character_,
construction_date = NA_character_,
aquifer_code = NA_character_,
national_aquifer_code = NA_character_,
aquifer_type_code = NA_character_,
well_constructed_depth = NA_character_,
read_waterdata_monitoring_location 69
hole_constructed_depth = NA_character_,
depth_source_code = NA_character_,
properties = NA_character_,
bbox = NA,
limit = NA,
max_results = NA,
skipGeometry = NA
)
Arguments
monitoring_location_id
A unique identifier representing a single monitoring location. This corresponds
to the id field in the monitoring-locations endpoint. Monitoring location
IDs are created by combining the agency code of the agency responsible for the
monitoring location (e.g. USGS) with the ID number of the monitoring location
(e.g. 02238500), separated by a hyphen (e.g. USGS-02238500).
agency_code The agency that is reporting the data. Agency codes are fixed values assigned
by the National Water Information System (NWIS). A list of agency codes is
available at this link.
agency_name The name of the agency that is reporting the data.
monitoring_location_number
Each monitoring location in the USGS data base has a unique 8- to 15-digit
identification number. Monitoring location numbers are assigned based on this
logic.
monitoring_location_name
This is the official name of the monitoring location in the database. For well
information this can be a district-assigned local number.
district_code The Water Science Centers (WSCs) across the United States use the FIPS state
code as the district code. In some case, monitoring locations and samples may
be managed by a water science center that is adjacent to the state in which the
monitoring location actually resides. For example a monitoring location may
have a district code of 30 which translates to Montana, but the state code could
be 56 for Wyoming because that is where the monitoring location actually is
located.
country_code The code for the country in which the monitoring location is located.
country_name The name of the country in which the monitoring location is located.
state_code State code. A two-digit ANSI code (formerly FIPS code) as defined by the
American National Standards Institute, to define States and equivalents. A three-
digit ANSI code is used to define counties and county equivalents. A lookup
table is available. The only countries with political subdivisions other than the
US are Mexico and Canada. The Mexican states have US state codes ranging
from 81-86 and Canadian provinces have state codes ranging from 90-98.
state_name The name of the state or state equivalent in which the monitoring location is
located.
county_code The code for the county or county equivalent (parish, borough, etc.) in which
the monitoring location is located. A list of codes is available.
70 read_waterdata_monitoring_location
county_name The name of the county or county equivalent (parish, borough, etc.) in which
the monitoring location is located. A list of codes is available.
minor_civil_division_code
Codes for primary governmental or administrative divisions of the county or
county equivalent in which the monitoring location is located.
site_type_code A code describing the hydrologic setting of the monitoring location. A list of
codes is available.
site_type A description of the hydrologic setting of the monitoring location. A list of
codes is available.
hydrologic_unit_code
The United States is divided and sub-divided into successively smaller hydro-
logic units which are classified into four levels: regions, sub-regions, accounting
units, and cataloging units. The hydrologic units are arranged within each other,
from the smallest (cataloging units) to the largest (regions). Each hydrologic
unit is identified by a unique hydrologic unit code (HUC) consisting of two to
eight digits based on the four levels of classification in the hydrologic unit sys-
tem.
basin_code The Basin Code or "drainage basin code" is a two-digit code that further sub-
divides the 8-digit hydrologic-unit code. The drainage basin code is defined by
the USGS State Office where the monitoring location is located.
altitude Altitude of the monitoring location referenced to the specified Vertical Datum.
altitude_accuracy
Accuracy of the altitude, in feet. An accuracy of +/- 0.1 foot would be entered
as “.1”. Many altitudes are interpolated from the contours on topographic maps;
accuracies determined in this way are generally entered as one-half of the con-
tour interval.
altitude_method_code
Codes representing the method used to measure altitude. A list of codes is avail-
able.
altitude_method_name
The name of the the method used to measure altitude. A list of codes is available.
vertical_datum The datum used to determine altitude and vertical position at the monitoring
location. A list of codes is available.
vertical_datum_name
The datum used to determine altitude and vertical position at the monitoring
location. A list of codes is available.
horizontal_positional_accuracy_code
Indicates the accuracy of the latitude longitude values. A list of codes is avail-
able.
horizontal_positional_accuracy
Indicates the accuracy of the latitude longitude values. A list of codes is avail-
able.
horizontal_position_method_code
Indicates the method used to determine latitude longitude values. A list of codes
is available.
read_waterdata_monitoring_location 71
horizontal_position_method_name
Indicates the method used to determine latitude longitude values. A list of codes
is available.
original_horizontal_datum
Coordinates are published in EPSG:4326 / WGS84 / World Geodetic System
1984. This field indicates the original datum used to determine coordinates be-
fore they were converted. A list of codes is available.
original_horizontal_datum_name
Coordinates are published in EPSG:4326 / WGS84 / World Geodetic System
1984. This field indicates the original datum used to determine coordinates be-
fore they were converted. A list of codes is available.
drainage_area The area enclosed by a topographic divide from which direct surface runoff from
precipitation normally drains by gravity into the stream above that point.
contributing_drainage_area
The contributing drainage area of a lake, stream, wetland, or estuary monitoring
location, in square miles. This item should be present only if the contributing
area is different from the total drainage area. This situation can occur when part
of the drainage area consists of very porous soil or depressions that either allow
all runoff to enter the groundwater or traps the water in ponds so that rainfall
does not contribute to runoff. A transbasin diversion can also affect the total
drainage area.
time_zone_abbreviation
A short code describing the time zone used by a monitoring location.
uses_daylight_savings
A flag indicating whether or not a monitoring location uses daylight savings.
construction_date
Date the well was completed.
aquifer_code Local aquifers in the USGS water resources data base are identified by a geohy-
drologic unit code (a three-digit number related to the age of the formation, fol-
lowed by a 4 or 5 character abbreviation for the geologic unit or aquifer name).
Additional information is available at this link.
national_aquifer_code
National aquifers are the principal aquifers or aquifer systems in the United
States, defined as regionally extensive aquifers or aquifer systems that have the
potential to be used as a source of potable water. Not all groundwater monitoring
locations can be associated with a National Aquifer. Such monitoring locations
will not be retrieved using this search criteria. A list of National aquifer codes
and names is available.
aquifer_type_code
Groundwater occurs in aquifers under two different conditions. Where water
only partly fills an aquifer, the upper surface is free to rise and decline. These
aquifers are referred to as unconfined (or water-table) aquifers. Where water
completely fills an aquifer that is overlain by a confining bed, the aquifer is
referred to as a confined (or artesian) aquifer. When a confined aquifer is pene-
trated by a well, the water level in the well will rise above the top of the aquifer
(but not necessarily above land surface). Additional information is available at
this link.
72 read_waterdata_monitoring_location
well_constructed_depth
The depth of the finished well, in feet below land surface datum. Note: Not
all groundwater monitoring locations have information on Well Depth. Such
monitoring locations will not be retrieved using this search criteria.
hole_constructed_depth
The total depth to which the hole is drilled, in feet below land surface da-
tum. Note: Not all groundwater monitoring locations have information on Hole
Depth. Such monitoring locations will not be retrieved using this search criteria.
depth_source_code
A code indicating the source of water-level data. A list of codes is available.
properties A vector of requested columns to be returned from the query. Available options
are: geometry, id, agency_code, agency_name, monitoring_location_number,
monitoring_location_name, district_code, country_code, country_name, state_code,
state_name, county_code, county_name, minor_civil_division_code, site_type_code,
site_type, hydrologic_unit_code, basin_code, altitude, altitude_accuracy, alti-
tude_method_code, altitude_method_name, vertical_datum, vertical_datum_name,
horizontal_positional_accuracy_code, horizontal_positional_accuracy, horizon-
tal_position_method_code, horizontal_position_method_name, original_horizontal_datum,
original_horizontal_datum_name, drainage_area, contributing_drainage_area, time_zone_abbreviation,
uses_daylight_savings, construction_date, aquifer_code, national_aquifer_code,
aquifer_type_code, well_constructed_depth, hole_constructed_depth, depth_source_code.
bbox Only features that have a geometry that intersects the bounding box are se-
lected.The bounding box is provided as four or six numbers, depending on
whether the coordinate reference system includes a vertical axis (height or depth).
Coordinates are assumed to be in crs 4326. The expected format is a numeric
vector structured: c(xmin,ymin,xmax,ymax). Another way to think of it is
c(Western-most longitude, Southern-most latitude, Eastern-most longitude, Northern-
most longitude).
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
skipGeometry This option can be used to skip response geometries for each feature. The re-
turning object will be a data frame with no spatial information.
Examples
"state_name",
"country_name"))
read_waterdata_parameter_codes
Get USGS Parameter Code Information
Description
Parameter codes are 5-digit codes and associated descriptions used to identify the constituent mea-
sured and the units of measure. Some parameter code definitions include information about the
sampling matrix, fraction, and methods used to measure the constituent. Some parameters are
fixed-value (fxd) numeric codes having textual meaning (for example: parameter code 00041 is a
weather code parameter, code of 60 means rain), but more commonly represent a numeric value for
chemical, physical, or biological data.
Usage
read_waterdata_parameter_codes(
parameter_code = NA_character_,
parameter_name = NA_character_,
unit_of_measure = NA_character_,
parameter_group_code = NA_character_,
parameter_description = NA_character_,
medium = NA_character_,
statistical_basis = NA_character_,
weight_basis = NA_character_,
sample_fraction = NA_character_,
temperature_basis = NA_character_,
epa_equivalence = NA_character_,
74 read_waterdata_parameter_codes
properties = NA_character_,
limit = NA,
max_results = NA
)
Arguments
parameter_code Parameter code.
parameter_name Parameter short name.
unit_of_measure
Parameter reporting units defined to cooperate with descriptions by USEPA.
parameter_group_code
Categorical groupings of parameters by water-quality data type for display and
report ordering
parameter_description
Parameter description.
medium Parameter medium.
statistical_basis
Parameter statistical basis.
weight_basis Parameter weight basis.
sample_fraction
Parameter fraction.
temperature_basis
Parameter temperature basis.
epa_equivalence
Indicates the relationship of the USGS parameter code to the EPA code.
properties A vector of requested columns to be returned from the query. Available options
are: geometry, id, parameter_name, unit_of_measure, parameter_group_code,
parameter_description, medium, statistical_basis, time_basis, weight_basis, par-
ticle_size_basis, sample_fraction, temperature_basis, epa_equivalence.
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
Examples
# equivalent to read_waterdata_metadata("parameter-codes")
read_waterdata_samples 75
read_waterdata_samples
USGS Samples Data
Description
This function creates the call and gets the data for discrete water quality samples data service de-
scribed at https://waterdata.usgs.gov/download-samples/.
Usage
read_waterdata_samples(
monitoringLocationIdentifier = NA,
siteTypeCode = NA,
boundingBox = NA,
hydrologicUnit = NA,
activityMediaName = NA,
characteristicGroup = NA,
characteristic = NA,
characteristicUserSupplied = NA,
activityStartDateLower = NA,
activityStartDateUpper = NA,
countryFips = NA,
stateFips = NA,
countyFips = NA,
projectIdentifier = NA,
recordIdentifierUserSupplied = NA,
siteTypeName = NA,
usgsPCode = NA,
pointLocationLatitude = NA,
pointLocationLongitude = NA,
pointLocationWithinMiles = NA,
dataType = "results",
dataProfile = NA,
tz = "UTC",
76 read_waterdata_samples
convertType = TRUE
)
read_USGS_samples(
monitoringLocationIdentifier = NA,
siteTypeCode = NA,
boundingBox = NA,
hydrologicUnit = NA,
activityMediaName = NA,
characteristicGroup = NA,
characteristic = NA,
characteristicUserSupplied = NA,
activityStartDateLower = NA,
activityStartDateUpper = NA,
countryFips = NA,
stateFips = NA,
countyFips = NA,
projectIdentifier = NA,
recordIdentifierUserSupplied = NA,
siteTypeName = NA,
usgsPCode = NA,
pointLocationLatitude = NA,
pointLocationLongitude = NA,
pointLocationWithinMiles = NA,
dataType = "results",
dataProfile = NA,
tz = "UTC",
convertType = TRUE
)
Arguments
monitoringLocationIdentifier
A monitoring location identifier has two parts: the agency code and the location
number, separated by a dash (-). Location identifiers should be separated with
commas, for example: AZ014-320821110580701, CAX01-15304600, USGS-
040851385. Location numbers without an agency prefix are assumed to have
the prefix USGS.
siteTypeCode Site type code query parameter. See available options by running check_waterdata_sample_params("si
boundingBox North and South are latitude values; East and West are longitude values. A
vector of 4 (west, south, east, north) is expected. An example would be: c(-
92.8, 44.2, -88.9, 46.0).
hydrologicUnit Hydrologic Unit Codes (HUCs) identify physical areas within the US that drain
to a certain portion of the stream network. This filter accepts values containing
2, 4, 6, 8, 10 or 12 digits.
activityMediaName
Sample media refers to the environmental medium that was sampled or ana-
lyzed.
read_waterdata_samples 77
characteristicGroup
Characteristic group is a broad category describing the sample. See available op-
tions by running check_waterdata_sample_params("characteristicgroup")$characteristicGrou
characteristic Characteristic is a specific category describing the sample. See available options
by running check_waterdata_sample_params("characteristics")$characteristicName.
characteristicUserSupplied
Observed property is the USGS term for the constituent sampled and the prop-
erty name gives a detailed description of what was sampled. Observed property
is mapped to characteristicUserSupplied and replaces the parameter name and
pcode USGS previously used to describe discrete sample data. Find more in-
formation in the Observed Properties and Parameter Codes section of the Code
Dictionary found here: https://waterdata.usgs.gov/code-dictionary/.
activityStartDateLower
The service will return records with dates earlier than the value entered for ac-
tivityStartDateUpper. Can be an R Date object, or a string with format YYYY-
MM-DD. The logic is inclusive, i.e. it will also return records that match the
date.
activityStartDateUpper
The service will return records with dates later than the value entered for activ-
ityStartDateLower. Can be an R Date object, or a string with format YYYY-
MM-DD. The logic is inclusive, i.e. it will also return records that match the
date.
countryFips Country query parameter. Do not set redundant parameters. If another query pa-
rameter contains the country information, leave this parameter set to the default
NA. See available options by running check_waterdata_sample_params("countries"),
where the "id" field contains the value to use in the countryFips input.
stateFips State query parameter. To get a list of available state fips, run check_waterdata_sample_params("state
The "fips" can be created using the function stateCdLookup - for example:
stateCdLookup("WI", "fips"). FIPs codes for states take the format: Coun-
tryAbbrev:StateNumber, like US:55 for Wisconsin.
countyFips County query parameter. To get a list of available counties, run check_waterdata_sample_params("cou
The "Fips" can be created using the function countyCdLookup - for example:
countyCdLookup("WI", "Dane", "fips") for Dane County, WI. FIPs codes
for counties take the format: CountryAbbrev:StateNumber:CountyNumber, like
US:55:025 for Dane County, WI.
projectIdentifier
Project identifier query parameter. This information would be needed from prior
project information.
recordIdentifierUserSupplied
Record identifier, user supplied identifier. This information would be needed
from the data supplier.
siteTypeName Site type name query parameter. See available options by running check_param("sitetype")$typeName
usgsPCode USGS parameter code. See available options by running check_waterdata_sample_params("characte
pointLocationLatitude
Latitude for a point/radius query (decimal degrees). Must be used with pointLo-
cationLongitude and pointLocationWithinMiles.
78 read_waterdata_samples
pointLocationLongitude
Longitude for a point/radius query (decimal degrees). Must be used with point-
LocationLatitude and pointLocationWithinMiles.
pointLocationWithinMiles
Radius for a point/radius query. Must be used with pointLocationLatitude and
pointLocationLongitude
dataType Options include: "Results", "Monitoring locations", "Activities", "Projects", and
"Organizations".
dataProfile Profile depends on type. Options for "results" dataType are: "fullphyschem",
"basicphyschem", "fullbio", "basicbio", "narrow", "resultdetectionquantitation-
limit", "labsampleprep", "count". Options for "locations" are: "site" and "count".
Options for "activities" are "sampact", "actmetric", "actgroup", and "count". Op-
tions for "projects" are: "project" and "projectmonitoringlocationweight". Op-
tions for "organizations" are: "organization" and "count".
tz character to set timezone attribute of datetime. Default is UTC (properly ac-
counting for daylight savings times based on the data’s provided tz_cd column).
Possible values include "America/New_York","America/Chicago", "America/Denver","America/Los_Ang
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua",
"America/Phoenix", and "America/Metlakatla"
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 re-
turned as a character.
Examples
read_waterdata_ts_meta
Get USGS Time Series Metadata
Description
Daily data and continuous measurements are grouped into time series, which represent a collection
of observations of a single parameter, potentially aggregated using a standard statistic, at a single
monitoring location. This endpoint provides metadata about those time series, including their op-
erational thresholds, units of measurement, and when the earliest and most recent observations in a
time series occurred.
Usage
read_waterdata_ts_meta(
monitoring_location_id = NA_character_,
parameter_code = NA_character_,
parameter_name = NA_character_,
properties = NA_character_,
statistic_id = NA_character_,
last_modified = NA_character_,
begin = NA_character_,
end = NA_character_,
unit_of_measure = NA_character_,
computation_period_identifier = NA_character_,
computation_identifier = NA_character_,
thresholds = NA,
sublocation_identifier = NA_character_,
primary = NA_character_,
time_series_id = NA_character_,
web_description = NA_character_,
skipGeometry = NA,
limit = NA,
max_results = NA,
bbox = NA,
convertType = FALSE
)
Arguments
monitoring_location_id
A unique identifier representing a single monitoring location. This corresponds
to the id field in the monitoring-locations endpoint. Monitoring location
IDs are created by combining the agency code of the agency responsible for the
monitoring location (e.g. USGS) with the ID number of the monitoring location
(e.g. 02238500), separated by a hyphen (e.g. USGS-02238500).
80 read_waterdata_ts_meta
parameter_code Parameter codes are 5-digit codes used to identify the constituent measured and
the units of measure. A complete list of parameter codes and associated group-
ings can be found at https://help.waterdata.usgs.gov/codes-and-parameters/
parameters.
parameter_name A human-understandable name corresponding to parameter_code.
properties A vector of requested columns to be returned from the query. Available op-
tions are: geometry, id, unit_of_measure, parameter_name, parameter_code,
statistic_id, last_modified, begin, end, computation_period_identifier, computa-
tion_identifier, thresholds, sublocation_identifier, primary, monitoring_location_id,
web_description, parameter_description
statistic_id A code corresponding to the statistic an observation represents. Example codes
include 00001 (max), 00002 (min), and 00003 (mean). A complete list of codes
and their descriptions can be found at https://help.waterdata.usgs.gov/
code/stat_cd_nm_query?stat_nm_cd=%25&fmt=html.
last_modified The last time a record was refreshed in our database. This may happen due to
regular operational processes and does not necessarily indicate anything about
the measurement has changed. You can query this field using date-times or
intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals
may be bounded or half-bounded (double-dots at start or end). Examples:
• A date-time: "2018-02-12T23:20:50Z"
• A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
• Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
• Duration objects: "P1M" for data from the past month or "PT36H" for the
last 36 hours
Only features that have a last_modified that intersects the value of datetime
are selected. If a feature has multiple temporal properties, it is the decision of the
server whether only a single temporal property is used to determine the extent
or all relevant temporal properties.
begin The datetime of the earliest observation in the time series. Together with end,
this field represents the period of record of a time series. Note that some time
series may have large gaps in their collection record. This field is currently in
the local time of the monitoring location. We intend to update this in version v0
to use UTC with a time zone.
end The datetime of the most recent observation in the time series. Data returned by
this endpoint updates at most once per day, and potentially less frequently than
that, and as such there may be more recent observations within a time series than
the time series end value reflects. Together with begin, this field represents the
period of record of a time series. It is additionally used to determine whether a
time series is "active". We intend to update this in version v0 to use UTC with
a time zone.
unit_of_measure
A human-readable description of the units of measurement associated with an
observation.
computation_period_identifier
Indicates the period of data used for any statistical computations.
read_waterdata_ts_meta 81
computation_identifier
Indicates whether the data from this time series represent a specific statistical
computation.
thresholds Thresholds represent known numeric limits for a time series, for example the
historic maximum value for a parameter or a level below which a sensor is non-
operative. These thresholds are sometimes used to automatically determine if an
observation is erroneous due to sensor error, and therefore shouldn’t be included
in the time series.
sublocation_identifier
An optional human-readable identifier used to specify where measurements are
recorded at a monitoring location.
primary A flag identifying if the time series is a "primary" time series. "Primary" time
series (which have this flag) are standard observations which undergo Bureau re-
view and approval processes. Non-primary time series, which will have missing
values for "primary", are provisional datasets made available to meet the need
for timely best science and to assist with daily operations which need real-time
information. Non-primary time series data are only retained by this system for
120 days. See the USGS Provisional Data Statement for more information.
time_series_id A unique identifier representing a single time series. This corresponds to the id
field in the time-series-metadata endpoint.
web_description
A description of what this time series represents, as used by WDFN and other
USGS data dissemination products.
skipGeometry This option can be used to skip response geometries for each feature. The re-
turning object will be a data frame with no spatial information.
limit The optional limit parameter is used to control the subset of the selected features
that should be returned in each page. The maximum allowable limit is 10000. It
may be beneficial to set this number lower if your internet connection is spotty.
The default (NA) will set the limit to the maximum allowable limit for the service.
max_results The optional maximum number of rows to return. This value must be less than
the requested limit.
bbox Only features that have a geometry that intersects the bounding box are se-
lected.The bounding box is provided as four or six numbers, depending on
whether the coordinate reference system includes a vertical axis (height or depth).
Coordinates are assumed to be in crs 4326. The expected format is a numeric
vector structured: c(xmin,ymin,xmax,ymax). Another way to think of it is
c(Western-most longitude, Southern-most latitude, Eastern-most longitude, Northern-
most longitude).
convertType logical, defaults to TRUE. If TRUE, the function will convert the data to dates and
qualifier to string vector.
Examples
renameNWISColumns renameColumns
Description
Rename columns coming back from NWIS data retrievals. Daily and unit value columns have
names derived from their data descriptor, parameter, and statistic codes. This function reads infor-
mation from the header and the arguments in the call to to rename those columns.
Usage
renameNWISColumns(
rawData,
p00010 = "Wtemp",
p00045 = "Precip",
p00060 = "Flow",
p00065 = "GH",
p00095 = "SpecCond",
p00300 = "DO",
p00400 = "pH",
p62611 = "GWL",
p63680 = "Turb",
p72019 = "WLBLS",
...
)
Arguments
rawData the daily- or unit-values datset retrieved from NWISweb.
p00010 the base name for parameter code 00010.
p00045 the base name for parameter code 00045.
p00060 the base name for parameter code 00060.
p00065 the base name for parameter code 00065.
p00095 the base name for parameter code 00095.
renameNWISColumns 83
Value
A dataset like data with selected columns renamed.
Note
The following statistics codes are converted by renameNWISColumns.
00000 Instantaneous Value, suffix: Inst
00001 Maximum value, suffix: Max
00002 Minimum value, suffix: Min
00003 Mean value, no suffix
00006 Sum of values, suffix: Sum
00007 Modal value, suffix: Mode
00008 Median value, suffix: Median
00012 Equivalent mean value, suffix: EqMean
00021 Tidal high-high value, suffix: HiHiTide
00022 Tidal low-high value, suffix: LoHiTide
00023 Tidal high-low value, suffix: HiLoTide
00024 Tidal low-low value, suffix: LoLoTide
See Also
readNWISdv(), readNWISuv()
Examples
siteWithTwo <- "01480015"
startDate <- "2012-09-01"
endDate <- "2012-10-01"
Description
access Indicate which dataRetrieval access code you want to use options: c('public','internal')
Usage
setAccess(access = "public")
Arguments
access code for data access. Options are: "public","internal","cooperator", or "USGS".
• "internal" represents Access=3 ...for a single water science center
• "USGS" represents Access=2 ...for all water science centers
• "cooperator" represents Access=1
• "public" represents Access=0, public access
Author(s)
Luke Winslow, Jordan S Read
Examples
setAccess("internal")
setAccess("public")
Description
Classic lookup table for states. Has been replaced in functions with check_waterdata_sample_params("states").
stateCdLookup 85
Value
stateCd data frame.
Examples
head(stateCd)
Description
Function to simplify finding state and state code definitions. Used in readNWISdata and readWQPdata.
Usage
stateCdLookup(input, outputType = "postal", country = "US")
Arguments
input could be character (full name, abbreviation, id), or numeric (id)
outputType character can be "postal", "fullName", "tableIndex", or "id".
country description
Examples
summarize_waterdata_samples
USGS Samples Summary Data
Description
This function creates the call and gets the data for discrete water quality samples summary data
service described at https://api.waterdata.usgs.gov/samples-data/docs.
Usage
summarize_waterdata_samples(monitoringLocationIdentifier)
summarize_USGS_samples(monitoringLocationIdentifier)
Arguments
monitoringLocationIdentifier
A monitoring location identifier has two parts, separated by a dash (-): the
agency code and the location number. Location identifiers should be separated
with commas, for example: AZ014-320821110580701, CAX01-15304600, USGS-
040851385. Location numbers without an agency prefix are assumed to have the
prefix USGS.
Value
data frame with summary of data available based on the monitoringLocationIdentifier
Examples
Description
Imports a table of available parameters, period of record, and count. See https://waterservices.
usgs.gov/docs/site-service/ for more information.
whatNWISdata 87
Usage
whatNWISdata(..., convertType = TRUE)
Arguments
... see https://waterservices.usgs.gov/docs/site-service/ for a complete
list of options. A list of arguments can also be supplied.
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 re-
turned as a character
Details
This function requires users to create their own arguments based on the NWIS web services. It
is a more complicated function to use compared to other NWIS functions such as readNWISdv(),
readNWISuv(), etc. However, this function adds a lot of flexibility to the possible queries. If the
"service" argument is included, the results will be filtered to the proper data_type_cd. This is a great
function to use before a large data set, by filtering down the number of sites that have useful data.
Value
A data frame with the following columns:
There are also several useful attributes attached to the data frame:
See Also
read_waterdata_ts_meta()
Examples
# see ?read_waterdata_ts_meta
Description
Returns a list of sites from the NWIS web service. This function gets the data from: https:
//waterservices.usgs.gov/docs/site-service/. Mapper format is used
Usage
whatNWISsites(...)
whatWQPdata 89
Arguments
... see https://waterservices.usgs.gov/docs/site-service/ for a complete
list of options. A list (or lists) can also be supplied.
Value
A data frame with at least the following columns:
Name Type Description
agency_cd character The NWIS code for the agency reporting the data
site_no character The USGS site number
station_nm character Station name
site_tp_cd character Site type code
dec_lat_va numeric Decimal latitude
dec_long_va numeric Decimal longitude
queryTime POSIXct Query time
There are also several useful attributes attached to the data frame:
Name Type Description
url character The url used to generate the data
queryTime POSIXct The time the data was returned
See Also
read_waterdata_monitoring_location()
Examples
# see ?read_waterdata_monitoring_location
#siteListPhos <- whatNWISsites(stateCd = "OH", parameterCd = "00665")
#oneSite <- whatNWISsites(sites = "05114000")
Description
Returns a list of sites from the Water Quality Portal web service. This function gets the data from:
https://www.waterqualitydata.us. Arguments to the function should be based on https://
www.waterqualitydata.us/webservices_documentation. The information returned from whatWQP-
data describes the available data at the WQP sites, and some metadata on the sites themselves. For
example, a row is returned for each individual site that fulfills this query. In that we can learn
how many sampling activities and results are available for the query. It does not break those re-
sults down by any finer grain. For example, if you ask for "Nutrients" (characteristicGroup), you
will not learn what specific nutrients are available at that site. For that kind of data discovery see
readWQPsummary.
90 whatWQPdata
Usage
whatWQPdata(..., convertType = TRUE)
Arguments
... see https://www.waterqualitydata.us/webservices_documentation for
a complete list of options. A list of arguments can also be supplied. One way to
figure out how to construct a WQP query is to go to the "Advanced" form in the
Water Quality Portal: https://www.waterqualitydata.us/#mimeType=csv&
providers=NWIS&providers=STORET Use the form to discover what parame-
ters are available. Once the query is set in the form, scroll down to the "Query
URL". You will see the parameters after "https://www.waterqualitydata.us/#".
For example, if you chose "Nutrient" in the Characteristic Group dropdown, you
will see characteristicType=Nutrient in the Query URL. The corresponding ar-
gument for dataRetrieval is characteristicType = "Nutrient". dataRetrieval users
do not need to include mimeType, and providers is optional (these arguments
are picked automatically).
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 re-
turned as a character.
Value
A data frame that returns basic data availability such as sites, number of results, and number of
sampling activities from the query parameters for the Water Quality Portal.
See Also
whatWQPsites readWQPsummary readWQPdata
Examples
Description
Returns a list of sites from the Water Quality Portal web service. This function gets the data from:
https://www.waterqualitydata.us. Arguments to the function should be based on https://
www.waterqualitydata.us/webservices_documentation. The return from this function returns
the basic metadata on WQP sites. It is generally faster than the whatWQPdata() function, but does
not return information on what data was collected at the site.
Usage
whatWQPsamples(..., convertType = TRUE, legacy = TRUE)
Arguments
... see https://www.waterqualitydata.us/webservices_documentation for
a complete list of options. A list of arguments can also be supplied. One way to
figure out how to construct a WQP query is to go to the "Advanced" form in the
Water Quality Portal: https://www.waterqualitydata.us/#mimeType=csv&
providers=NWIS&providers=STORET Use the form to discover what parame-
ters are available. Once the query is set in the form, scroll down to the "Query
URL". You will see the parameters after "https://www.waterqualitydata.us/#".
For example, if you chose "Nutrient" in the Characteristic Group dropdown, you
will see characteristicType=Nutrient in the Query URL. The corresponding ar-
gument for dataRetrieval is characteristicType = "Nutrient". dataRetrieval users
do not need to include mimeType, and providers is optional (these arguments
are picked automatically).
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 re-
turned as a character.
legacy Logical. If TRUE, uses legacy WQP services. Default is TRUE. Setting legacy
= FALSE uses WQX3.0 WQP services, which are in-development, use with
caution.
Value
A data frame with information on the sampling activity available from the Water Quality Portal for
the query parameters.
data frame that includes information on site metadata.
92 wqp_check_status
See Also
whatWQPdata readWQPsummary
whatNWISdata
Examples
Description
The information from this request is only available for a limited time after the original query from
the WQP. In the readWQPdata and readWQPqw functions, the results from this function will be
attached as an attribute to the data.
Usage
wqp_check_status(wqp_request_id)
zeroPad 93
Arguments
wqp_request_id A character returned from the header of a WQP request.
Value
a list generated from the WQP describing what data was returned.
Examples
Description
Function to pad a string with leading zeros. Useful for parameter codes and USGS site IDs.
Usage
zeroPad(x, padTo)
Arguments
x character
padTo number Final desired length of the character
Value
x character returned with leading zeros
Examples
pCode <- "10"
correctPCode <- zeroPad(pCode, 5)
pCodes <- c("100", "1000", "0", "12345", "1565465465465465")
correctPCodes <- zeroPad(pCodes, 5)
pCodeNA <- c(1, 2, NA)
padPCodeNA <- zeroPad(pCodeNA, 4)
Index
∗ IO readNWISuv, 47
renameNWISColumns, 82 readWQPdata, 50
∗ USGS readWQPqw, 55
constructNWISURL, 6 whatNWISdata, 86
countyCd, 10 whatWQPdata, 89
readNWISdv, 33 whatWQPsamples, 91
readNWISpCode, 39 zeroPad, 93
readNWISsite, 42 ∗ manip
readNWISuv, 47 renameNWISColumns, 82
readWQPqw, 55 ∗ nldi
stateCd, 84 findNLDI, 12
whatNWISdata, 86 get_nldi_sources, 16
zeroPad, 93 ∗ service
∗ WQP constructNWISURL, 6
constructWQPURL, 9 constructWQPURL, 9
readWQPdata, 50 readNWISdv, 33
whatWQPdata, 89 readNWISpCode, 39
whatWQPsamples, 91 readNWISsite, 42
∗ countyCd readNWISuv, 47
countyCd, 10 readWQPdata, 50
∗ data readWQPqw, 55
constructNWISURL, 6 whatNWISdata, 86
constructWQPURL, 9 whatWQPdata, 89
readNWISdv, 33 whatWQPsamples, 91
readNWISpCode, 39 zeroPad, 93
readNWISsite, 42 ∗ stateCd
readNWISuv, 47 stateCd, 84
readWQPdata, 50 ∗ web
readWQPqw, 55 constructNWISURL, 6
whatNWISdata, 86 constructWQPURL, 9
whatWQPdata, 89 readNWISdv, 33
whatWQPsamples, 91 readNWISpCode, 39
zeroPad, 93 readNWISsite, 42
∗ import readNWISuv, 47
constructNWISURL, 6 readWQPdata, 50
constructWQPURL, 9 readWQPqw, 55
readNWISdv, 33 whatNWISdata, 86
readNWISpCode, 39 whatWQPdata, 89
readNWISsite, 42 whatWQPsamples, 91
94
INDEX 95
zeroPad, 93 read_waterdata_ts_meta(), 88
readNGWMNdata, 26
addWaterYear, 3 readNGWMNlevels, 27
readNGWMNsites, 29
calcWaterYear, 4 readNWISdata, 30
check_waterdata_sample_params, 5 readNWISdata(), 33, 35, 48
checkWQPdates, 5 readNWISdv, 33
constructNWISURL, 6 readNWISdv(), 30, 83, 87
constructNWISURL(), 36, 38, 41, 42, 45 readNWISgwl, 35
constructUseURL, 8 readNWISgwl(), 30
constructWQPURL, 9 readNWISmeas, 37
countyCd, 10 readNWISpCode, 39
countyCdLookup, 10 readNWISpeak, 39
create_NWIS_bib, 11 readNWISrating, 41
create_WQP_bib, 12 readNWISsite, 42
readNWISstat, 44
findNLDI, 12
readNWISuse, 46
get_nldi_sources, 16 readNWISuv, 47
getQuerySummary, 14 readNWISuv(), 30, 83, 87
getWebServiceData, 15 readWQPdata, 50
readWQPdata(), 23, 56
importNGWMN, 16 readWQPqw, 55
importRDB1, 17 readWQPqw(), 23
importRDB1(), 36, 38, 39, 41, 42, 45 readWQPsummary, 57
importWaterML1, 19 renameNWISColumns, 82
importWaterML1(), 49 renameNWISColumns(), 20, 49
importWaterML2, 22
importWQP, 23 setAccess, 84
importWQP(), 56 stateCd, 84
is_dataRetrieval_user, 24 stateCdLookup, 85
summarize_USGS_samples
parameterCdFile, 24 (summarize_waterdata_samples),
parse_WQP, 25 86
pcode_to_name, 26 summarize_waterdata_samples, 86
read_USGS_samples whatNWISdata, 86
(read_waterdata_samples), 75 whatNWISdata(), 33, 35, 48
read_waterdata, 58 whatNWISsites, 88
read_waterdata(), 31 whatWQPdata, 89
read_waterdata_daily, 60 whatWQPdata(), 91
read_waterdata_daily(), 34 whatWQPmetrics (whatWQPsamples), 91
read_waterdata_latest_continuous, 63 whatWQPsamples, 91
read_waterdata_metadata, 66 whatWQPsites (whatWQPsamples), 91
read_waterdata_monitoring_location, 67 whatWQPsites(), 23, 56
read_waterdata_monitoring_location(), wqp_check_status, 92
44, 89
read_waterdata_parameter_codes, 73 zeroPad, 93
read_waterdata_samples, 75
read_waterdata_ts_meta, 79